Templates & phpBB3

Hulp nodig bij een stijl? Voor zowel XHTML/CSS als grafische vragen uiteraard gerelateerd aan phpBB3.
Forumregels

LEES: Richtlijnen voor Support. Vul de support template in!
phpBB3.0.x
Verschaf iemand geen servertoegang tenzij het niet anders kan. Maak altijd eerst een volledige backup en verander de inloggevens na afloop. Eigen risico.
Gesloten
Salomon
Berichten: 3878
Lid geworden op: 14 feb 2006, 16:15

Templates & phpBB3

Bericht door Salomon » 05 jun 2007, 17:48

Dit is een kleine handleiding over hoe je templates moet maken in phpBB3. Als je iets mist, meld het graag!
Voor vragen: Schroom niet om een nieuw topic te maken!

Bestandsnamen

In 3.0.x eindigen bestanden niet meer met ".tpl" maar ".html". Dit is oa gedaan om het voor sommige mensen makkelijker te maken deze bestanden te bewerken (highlighten van HTML bijvoorbeeld)

Variabelen

vars is de afkorting voor variabelen

De basis syntaxis voor variabelen (geen blokken zoals viewtopic) vars is hetzelfde als 2.0.x. Dat betekend dat variabelen ongeveer zo zijn opgebouwd: {X_YYYYY}. Deze variabelen worden (gedeeltelijk) toegewezen door het bijbehorende PHP bestand. Het verschil met 2.0.x is dat de meeste taalvariabelen niet zijn toegewezen in de PHP code! Als er {L_XXXXXX} in het HTML bestand staat, kijkt phpBB eerst of er een taalvariabele is toegewezen met die naam (de XXXXXX). Zoja, wordt de waarde daarvan gebruikt. Zonee, kijkt het of er in het taalbestand een variabele met die naam bestaat. Dit is gedaan om het toewijzen van taalvariabelen bij MOD's te verminderen.

Blokken

De basis van alle blokken ziet er zo uit:

Code: Selecteer alles

<!-- BEGIN loopname -->
markup, {loopname.X_YYYYY}, etc.
<!-- END loopname --> 
Spoiler: bekijk
However this has now been extended with the following additions. Firstly you can set the start and end points of the loop. For example:

Code: Selecteer alles

<!-- BEGIN loopname(2) -->
markup
<!-- END loopname -->
Will start the loop on the third entry (note that indexes start at zero). Extensions of this are:

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: Selecteer alles

<!-- BEGIN loop -->
markup
<!-- BEGINELSE -->
markup
<!-- END loop -->
This will cause the markup between BEGINELSE and END to be output if the loop contains no values. This is useful for forums with no topics (for example) ... in some ways it replaces "bits of" the existing "switch_" type control (the rest being replaced by conditionals, see below).

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: Selecteer alles

<!-- INCLUDE filename -->
You will note in the 2.2 templates the major sources start with INCLUDE overall_header.html or INCLUDE simple_header.html, etc. In 2.0.x control of "which" header to use was defined entirely within the code. In 2.2.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common "menu" bar or some such. No need to modify loads of files as with 2.0.x

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: Selecteer alles

<!-- PHP -->
echo "hello!";
<!-- ENDPHP -->
You may also include PHP from an external file using:

Code: Selecteer alles

<!-- INCLUDEPHP somefile.php -->
it will be included and executed inline.

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: Selecteer alles

<!-- IF expr -->
markup
<!-- ENDIF -->
expr can take many forms, for example:

Code: Selecteer alles

<!-- IF loop.S_ROW_COUNT is even -->
markup
<!-- ENDIF -->
This will output the markup if the S_ROW_COUNT variable in the current iteration of loop is an even value (i.e. the expr is TRUE). You can use various comparison methods (standard as well as equivalent textual versions noted in square brackets) including:

== [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: Selecteer alles

<!-- IF expr1 -->
markup
<!-- ELSEIF expr2 -->
markup
.
.
.
<!-- ELSEIF exprN -->
markup
<!-- ELSE -->
markup
<!-- ENDIF -->
Each statement will be tested in turn and the relevant output generated when a match (if a match) is found. It is not necessary to always use ELSEIF, ELSE can be used alone to match "everything else".

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: Selecteer alles

<table>
<!-- IF loop.S_ROW_COUNT is even -->
<tr class="row1">
<!-- ELSE -->
<tr class="row2">
<!-- ENDIF -->
<td>HELLO!</td>
</tr>
</table>
This will cause the row cell to be output using class row1 when the row count is even, and class row2 otherwise. Big deal you say, 2.0.x did that! True, but here you are not limited to using class row1 or row2 ... you can use any defined class, set your own inline style, etc. What's more you are not limited to two row colours at all ... e.g.

Code: Selecteer alles

<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>
This will output the row cell in purple for the first two rows, blue for rows 2 to 5, green for rows 5 to 10 and red for remainder. So, you could produce a "nice" gradient effect, for example.

What else can you do? Well, you could use IF to do common checks on for example the login state of a user:

Code: Selecteer alles

<!-- IF S_USER_LOGGED_IN -->
markup
<!-- ENDIF -->
This replaces the existing (fudged) method in 2.0.x using a zero length array and BEGIN/END.
Het gedeelte hierboven, in spoiler, is nog niet vertaald. Dit zal ik zeer binnenkort doen, hulp per PM is welkom!


Oorspronkelijke maker psoTFX, was vroeger development team leader (nu Acyd Burn). Bron: dit topic op area51

Coen
Berichten: 5387
Lid geworden op: 03 aug 2004, 10:25

Re: Templates & phpBB3

Bericht door Coen » 14 jun 2007, 11:12

Is dit niet meer een artikel voor de Wiki? Ik vind het natuurlijk allemaal prima, dat je het hier post, maar lijkt me praktischer en beter te onderhouden als je het in de Wiki zet... :roll:

ElbertF
Berichten: 5803
Lid geworden op: 12 okt 2004, 08:34
Contacteer:

Re: Templates & phpBB3

Bericht door ElbertF » 14 jun 2007, 12:35

Staat er toch ook inmiddels?

Coen
Berichten: 5387
Lid geworden op: 03 aug 2004, 10:25

Re: Templates & phpBB3

Bericht door Coen » 14 jun 2007, 12:40

ElbertF schreef:Staat er toch ook inmiddels?
Weet ik niet, maar ik vroeg het me gewoon af, waarom hij hier stond en niet in de Wiki... :P

Ik ben blijkbaar niet de enige die Wiki-artikelen voorbereid in het forum! ;)

Gebruikersavatar
Stef
Berichten: 9080
Lid geworden op: 04 jun 2003, 20:47

Re: Templates & phpBB3

Bericht door Stef » 13 jul 2007, 13:28

Precies, dit kan men lezen in de wiki: [wiki]phpBB3:Template parser[/wiki].

Gesloten