Interface

Template

Package: io Author: Benoit Sautel <ben.popeye@phpboost.com> Desc: 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: <h1>Variable assignation</h1> <h2>Simple variables</h2> 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. <h1>Lang variables</h1> 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. <h2>Loops</h2> 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. <h2>Conditions</h2> 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. <h3>Nesting templates</h3> 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. <h1>Variables using</h1> 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:
  • <E_: the variable will be searched without its prefix and will be escaped using <span class="php-keyword2">htmlspecialchars</span>()
  • <J_: the variable will be searched without its prefix and will be escaped using TextHelper::to_js_string()
  • <L_: the variable will be searched without its prefix in every languages maps registered using Template->add_lang(<span class="php-var">$language</span>)
  • <EL_: the variable will be searched without its prefix like languages variables and will be escaped using <span class="php-keyword2">htmlspecialchars</span>()
  • <JL_: the variable will be searched without its prefix like languages variables and will be escaped using TextHelper::to_js_string()
Located at io/template/Template.class.php
Template implements View

Direct known implementers

AbstractTemplate

Indirect known implementers

FileTemplate, StringTemplate
Methods summary
public
# enable_strict_mode( )
public
# disable_strict_mode( )
public
# put( mixed $key, mixed $value )
public
# put_all( array $vars )
public
# assign_block_vars( string $block_name, array $array_vars, array $subtemplates = array() )
public
# display( )
public
# add_lang( array $lang )
public
# set_data( TemplateData $data )
public TemplateData
# get_data( )
public String
# get_pictures_data_path( )
Methods inherited from View
render()