Package IO\Template

Package IO\Template

Classes summary
AbstractTemplate

This class is a default implementation of the Template interface using a TemplateLoader, a TemplateData and a TemplateParser.

FileTemplate

This class allows you to handle a template file. Your template files should have the .tpl extension. To be more efficient, this class uses a cache and parses each file only once.

File identifiers

The web site can have several themes whose files aren't in the same folders. When you load a file, you just have to load the generic file and the right template file will be loaded dynamically.

Kernel template file

When you want to load a kernel template file, the path you must indicate is only the name of the file, for example header.tpl loads /template/your_theme/header.tpl and if it doesn't exist, it will load /template/default/header.tpl.

Module template file

When you want to load a module template file, you must indicate the name of you module and then the name of the file like this: module/file.tpl which will load the /module/templates/file.tpl. If the user themes redefines the file.tpl file for the module module, the file templates/your_theme/modules/module/file.tpl will be loaded.

Menu template file

To load a file of a menu, use this kind of path: menus/my_menu/file.tpl which will load the /menus/my_menu/templates/file.tpl file.

Framework template file

To load a framework file, use a path like this: framework/package/file.tpl which will load /templates/your_theme/framework/package/file.tpl if the theme overrides it, otherwise /templates/default/framework/package/file.tpl will be used.

I18NMessages
StringTemplate

This class enables you to handle a template whose input is not a file but directly a string. To be always as efficient as possible, it uses cache if it evaluates that it could be faster. But when string templates are cached, they are saved on the filesystem and use some disk space. It's the reason why there is an option enabling to forbid it to cache a template if you think that it's not required to have a big efficiency. It will be the case for instance when you know that a string template will be used only once a month.

TemplateFunctions
Interfaces summary
Template

This class represents a PHPBoost template. Templates are used to generate text which have a common structure. You just have to write your text with tags at the place you want to insert values and assign values in the objet, when you will display them, the tags will be replaced by the corresponding value. PHPBoost's template engine is home made and has its own syntax which is the described below:

Variable assignation

Simple variables

A simple variable is accessible with the {NAME} syntax where NAME is its template name. If the variable is not assigned, nothing will be displayed (no error message). Simple variables are assigned by the assign_vars() method.

Lang variables

To speed the development up, you can avoid setting all the localized variables to use. You just have to associate one or more lang map (lang_identifier => localized lang) with the Template::add_lang() method. In the template, you just have to add the 'L_' prefix before the variable name and it will be searched in the langs map.

Loops

You can make some loops to repeat a pattern, those loops can be nested. A loop has a name (name) and each iteration contains some variables, for example, the variable VAR.
# START name #
My variable is {name.VAR}
# END name #
To nest loops, here is an example:
# START loop1 #
I write my loop1 var here: {loop1.VAR}.
# START loop1.loop2 #
I can write my loop2 var here: {loop1.loop2.VAR} but also my loop1 var of the parent loop: {loop1.VAR}.
# END loop1.loop2 #
# END loop1 # To assign the variable, see the assign_block_vars() method which creates one iteration.

Conditions

When you want to display something only in particular case, you can use some condition tests.
# IF C_MY_TEST #
This text will be displayed only if the C_MY_TEST variable is true
# ENDIF # You can nest some conditions.

Nesting templates

You can embed a template in another one. For that, you have to use the INCLUDE instruction like that: # INCLUDE template # where template is the identifier of a template added with the add_subtemplate() method. When the template will be displayed, this instruction will be replaced by the content of the template you have attached to this identifier or nothing if the template hasn't been set. You also can include templates in a loop, for that you have to place them in the third parameter of the asssign_block_vars() method.

Variables using

By default, when you call the variable by it's name, it'll be returnes as it was assigned. But you can do little implicit treatments of variables directly in the template. Here are the prefixes to use before the variable names:

  • htmlspecialchars()
  • TextHelper::to_js_string()
  • Template->add_lang($language)
  • htmlspecialchars()
  • TextHelper::to_js_string()
View
Annonces