File naming
Firstly templates now take the suffix ".html" rather than ".tpl". This was done simply to make the lifes of some people easier wrt syntax highlighting, etc.
Variables
The basic syntax for simple (non-block) vars remains the same as with 2.0.x. That is variables take the form {X_YYYYY} with the data being assigned from the source. Note that unlike 2.0.x most language strings are not assigned from the source. When a language variable is found {L_YYYYYY} phpBB first looks if an assigned variable exists with that name. If it does, it uses that. If not it looks if an exsting string defined in the language file exists. This should reduce the need to assign loads of new lang vars in Mods.
Blocks
The basic block level loop remains and takes the form:
Code: Select all
<!-- BEGIN loopname -->
markup, {loopname.X_YYYYY}, etc.
<!-- END loopname -->
Code: Select all
<!-- BEGIN loopname(2) -->
markup
<!-- END loopname -->
loopname(2,4): Starts loop on third values, ends on fourth
loopname(-4): Starts loop fourth from last value
loopname(2, -4): Starts loop on third value, ends four from end
Note that the indexing method may change since it's not really consistent at this time
A further extension to begin is BEGINELSE:
Code: Select all
<!-- BEGIN loop -->
markup
<!-- BEGINELSE -->
markup
<!-- END loop -->
Including files
Something that existed in 2.0.x which no longer exists in 2.2.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:
Code: Select all
<!-- INCLUDE filename -->
PHP
A contentious decision has seen the ability to include PHP within the template introduced. This is achieved by enclosing the PHP within relevant tags:
Code: Select all
<!-- PHP -->
echo "hello!";
<!-- ENDPHP -->
Code: Select all
<!-- INCLUDEPHP somefile.php -->
A note, it is very much encouraged that template designers do not include PHP. The ability to include raw PHP was introduced primarily to allow end users to include banner code, etc. without modifing multiple files (as with 2.0.x). It was not intended for general use ... hence http://www.phpbb.com" target="_blank will not make available template sets which include PHP. And by default templates will have PHP disabled (the admin will need to specifically activate PHP for a template).
Conditionals/Control structures
The most significant addition to 2.2.x are conditions or control structures, "if something then do this else do that". The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:
Code: Select all
<!-- IF expr -->
markup
<!-- ENDIF -->
Code: Select all
<!-- IF loop.S_ROW_COUNT is even -->
markup
<!-- ENDIF -->
== [eq]
!= [neq, ne]
<> (same as !=)
!== (not equivalent in value and type)
=== (equivalent in value and type)
> [gt]
< [lt]
>= [gte]
<= [lte]
&& [and]
|| [or]
% [mod]
! [not]
+
-
*
/
<< (bitwise shift left)
>> (bitwise shift right)
| (bitwise or)
^ (bitwise xor)
& (bitwise and)
~ (bitwise not)
is (can be used to join comparison operations)
Basic parenthesis can also be used to enforce good old BODMAS rules. Additionally some basic comparison types are defined:
even
odd
div
Beyond the simple use of IF you can also do a sequence of comparisons using the following:
Code: Select all
<!-- IF expr1 -->
markup
<!-- ELSEIF expr2 -->
markup
.
.
.
<!-- ELSEIF exprN -->
markup
<!-- ELSE -->
markup
<!-- ENDIF -->
So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 2.2.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:
Code: Select all
<table>
<!-- IF loop.S_ROW_COUNT is even -->
<tr class="row1">
<!-- ELSE -->
<tr class="row2">
<!-- ENDIF -->
<td>HELLO!</td>
</tr>
</table>
Code: Select all
<table>
<!-- IF loop.S_ROW_COUNT > 10 -->
<tr bgcolor="#FF0000">
<!-- ELSEIF loop.S_ROW_COUNT > 5 -->
<tr bgcolor="#00FF00">
<!-- ELSEIF loop.S_ROW_COUNT > 2 -->
<tr bgcolor="#0000FF">
<!-- ELSE -->
<tr bgcolor="#FF00FF">
<!-- ENDIF -->
<td>hello!</td>
</tr>
</table>
What else can you do? Well, you could use IF to do common checks on for example the login state of a user:
Code: Select all
<!-- IF S_USER_LOGGED_IN -->
markup
<!-- ENDIF -->
Overview
So as noted this a brief overview of some of the changes in templates made for 2.2.x.