Robbo
Well-known member
[WIP] - will finish when I get time
Note: the following is a simple overview of how XenForo syntax is compiled into PHP aimed at developers so that they have a better understanding of how it works and therefore avoid problems that may occur from the black box. Which brings me to the next line...
If you just want reference to the syntax scroll down and skip this first post.
Simple Overview
XenForo uses simple yet powerful templating syntax. There are 3 different additions to the HTML and CSS. Firstly a 'xen' namespace that has a list of tags you can use to do various things. Secondly functions with the syntax {xen:functionName [arguments seperated by commas]}. And thirdly, for styling you can access style properties by using the @ character followed by the style property.
XenForo will also compile {$varName} to a variable available to the current template.
XenForo compiles this stuff into PHP and stores the compiled templates in the database. There is also an option to copy the compiled templates into files and use them instead to take advantage of OPCaches.
Tags
Tags are the same as using HTML. You simply specify the tag and add its attributes and values. When run through the compiler tags take into account all the attributes and children (if any) to produce PHP to be appended to the templates compiled source.
The following is an example of how <xen:set> works. Firstly the use of <xen:set> is to create a new variable to use within templates. So <xen:set var="$foo">1</xen:set>. When the compiler runs it picks up this tag and firstly looks to make sure the attribute var is set. If it is it simply creates a new variable which is the name of whatever var is, so in this case $foo. Then the compiler calls a method which takes all the children of <xen:set> and processors it into the variable that was already created. Although this only works with scalar values when using <xen:set>. So in our case it would simply do $foo = '1'; . This then goes through a couple methods to place it properly in the compiled template.
Functions
XenForo can't do everything with XML tags. For this they have functions. Functions follow the syntax of {xen:functionName arg1, arg2 ... }. Think of this the same as PHP functions, functionName(arg1, arg2 ...). When compiled they are done in much the same way as tags except instead of attributes you have arguments and there are no children to a function. Because of this I don't see the need for another example, the <xen:set> example above describes how compiling works well enough for this little tutorial (article?).
Style Properties
I'm not going to go into much detail here as there isn't much to go into. These are simply things like @imagePath which when compiled are turned into a static method call to get the value of a style property. For @imagePath the compiled template will contain XenForo_Template_Helper_Core::styleProperty('imagePath').
Note: the following is a simple overview of how XenForo syntax is compiled into PHP aimed at developers so that they have a better understanding of how it works and therefore avoid problems that may occur from the black box. Which brings me to the next line...
If you just want reference to the syntax scroll down and skip this first post.
Simple Overview
XenForo uses simple yet powerful templating syntax. There are 3 different additions to the HTML and CSS. Firstly a 'xen' namespace that has a list of tags you can use to do various things. Secondly functions with the syntax {xen:functionName [arguments seperated by commas]}. And thirdly, for styling you can access style properties by using the @ character followed by the style property.
XenForo will also compile {$varName} to a variable available to the current template.
XenForo compiles this stuff into PHP and stores the compiled templates in the database. There is also an option to copy the compiled templates into files and use them instead to take advantage of OPCaches.
Tags
Tags are the same as using HTML. You simply specify the tag and add its attributes and values. When run through the compiler tags take into account all the attributes and children (if any) to produce PHP to be appended to the templates compiled source.
The following is an example of how <xen:set> works. Firstly the use of <xen:set> is to create a new variable to use within templates. So <xen:set var="$foo">1</xen:set>. When the compiler runs it picks up this tag and firstly looks to make sure the attribute var is set. If it is it simply creates a new variable which is the name of whatever var is, so in this case $foo. Then the compiler calls a method which takes all the children of <xen:set> and processors it into the variable that was already created. Although this only works with scalar values when using <xen:set>. So in our case it would simply do $foo = '1'; . This then goes through a couple methods to place it properly in the compiled template.
Functions
XenForo can't do everything with XML tags. For this they have functions. Functions follow the syntax of {xen:functionName arg1, arg2 ... }. Think of this the same as PHP functions, functionName(arg1, arg2 ...). When compiled they are done in much the same way as tags except instead of attributes you have arguments and there are no children to a function. Because of this I don't see the need for another example, the <xen:set> example above describes how compiling works well enough for this little tutorial (article?).
Style Properties
I'm not going to go into much detail here as there isn't much to go into. These are simply things like @imagePath which when compiled are turned into a static method call to get the value of a style property. For @imagePath the compiled template will contain XenForo_Template_Helper_Core::styleProperty('imagePath').