|
|
Template filesTemplate files are basic text files. By convention the extension .tpl is used, but this isn't a requirement for the parser. Note that the .tpl extension is mandatory for usage in skins. Right now, the parser is only used for skins to convert from HTML->HTML, but it could also be used for templating in the apache, bind, sendmail, etc. configuration files. In order to use the features of the parser, you haev to include tags into the template. Tags consist of text surrounded two accolades (Example: {tag}). Right now there are 7 (or 8) different types of tags: 3 basic and 4 special tags. The parser will continue until there are no more replacable tags present. This means that if something gets replace by text which itself contains a valid tag, that new tag will also get replace. This makes it possible to create infinite loops, so care should be taken, although it doesn't generally pose a problem. Basic tagsVariablesTemplate
PHP
Result
DescriptionThese are the most basic type of tags, any occurence of {var} will be replace by the replacement specified in the AddVar? call. Language VariablesTemplate
PHP
Result
DescriptionVariables beginning with L: are special. These are automatically replaced by the appropriate entry in the language files. ConditionalsTemplate
PHP
Result
DescriptionConditionals have two forms.
IterationTemplate<ul>
{/list} PHP
Result<ul>
</ul> DescriptionIteration is the most complex basic tag. All tag related methods have an optional last parameter which defined in which "class" they belong. In the example a variable is added to the class "list". Classes can also be nested inside other classes. Special tagsSpecial tags are used by template designers only and can only very limitedly be manipulated using code. CommentsExampleText {* this is a comment *} Text ResultText Text DescriptionEverything between {* and *} will not be output. It can be used to add comments to a file, or comment out unwanted parts of a template. IncludesExampleText {#other.tpl} Text Description{#file.tpl} will be replaced with the contents of file.tpl. That file will also be processed by the parser. WrappingExampleBefore {!main.tpl}Inside{/!main.tpl} After Example (main.tpl)MainBefore {main page} MainAfter ResultBefore MainBefore Inside MainAfter After DescrpitionEverything between the opening and closing tags will be replaced by the contents of the specified file. In addition, {main page} in that file will be replaced by whatever was inside the tags. Setting variablesExample{$var}Value{/$var} Var: {var} ResultVar: Value DescriptionThis may seem pretty useless, but allows you to specify variables for other files. This becomes useful in combination with {!main.tpl} if for example main.tpl contains a {title} tag. Notice: "unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 2299 of 2318 bytes" (...repeated 2 times) |