Interface

Template

Package: IO\Template Copyright: © 2005-2019 PHPBoost License: GNU/GPL-3.0 Author: Benoit SAUTEL ben.popeye@phpboost.com Version: PHPBoost 5.2 - last update: 2014 12 22 Since: PHPBoost 3.0 - 2010 02 03 Located at: io/template/Template.class.php

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()
Template implements View
Direct known implementers
AbstractTemplate
Indirect known implementers
FileTemplate, StringTemplate
Methods summary
public
# enable_strict_mode( )

Enables the strict mode. If a variable that does not exist in the object is requested, then an exception will be raised.

public
# disable_strict_mode( )

Disables the strict mode. If a variable that does not exist in the object is requested, then an empty value will be returned.

public
# put( $key, $value )

Assigns the value

$code

to the template variable of name

$key
public
# put_all( array $vars )

Assigns template variables. It could be simple variables, loop or subtemplates.

public
# assign_vars( array $array_vars )
public
# assign_block_vars( string $block_name, array $array_vars, array $subtemplates = array() )

Assigns a template block. A block represents a loop and has a name which be used in your template file to indicate which loop you want to browse. To know what syntax to use to browse a loop, see the class description, there are examples.

public
# display( )

Displays the template.

public
# add_lang( array $lang )

Adds a lang map to the template map list in which template variables beginning by L_ will be searched for of not already registered

public
# add_subtemplate( string $identifier, Template $template )
public
# set_data( TemplateData $data )

Inject data into the template. This is for internal use only.

public TemplateData
# get_data( )

Returns the template data

public String
# get_pictures_data_path( )

Returns the pictures data path

Methods inherited from View
render()
Annonces