Development Wiki

Template.assign vars

From phpBB Development Wiki

Revision as of 01:45, 23 September 2008 by 3di (Talk | contribs)

template::assign_vars –– Assign key variable pairs from an array to the template object.


  1. bool template::assign_vars ( array $vararray )

While language and template variables are automatically set, you will need to manually set other kinds of data you want to use in your template file. This is done by using the template object's assign_vars method.

Note: The means of transporting data to the template is the use of template variables.. By convention, template variable names are always all-uppercase. Variables output to the user are enclosed in curly braces (e.g. {L_SOME_VARIABLE}) while variables in control structures are used directly.


Parameter Usage
vararray Array containing keys and values. Keys are used within the template and the associated value will be displayed to the user.

Return Values

Returns true


Example #1

Variables assigned to the template object in your PHP file. (PHP Controller file)

'S_SOME_VARIABLE'   => $some_variable,
'NOW'               => $user->format_date(time()),

Example of usage of these variables within the HTML template:

<div>{SOME_VARIABLE}<br />{NOW}</div>


Naming Conventions

The naming conventions for template variables are:
* Template related variables are prefixed with "T_". These are usually pre-assigned by the phpBB3 core code.
* Variables to be used in control structures or for form actions etc. are prefixed with "S_".
* Variables containing URls are prefixed with "U_".
* Language variables for output are called "L_LANGUAGE_KEY". Where "LANGUAGE_KEY is an existing language entry's key. These are assigned automatically.
* Language variables for use in javascript are called "LA_LANGUAGE_KEY". Where "LANGUAGE_KEY is an existing language entry's key. These are assigned automatically.
* Values for display are not prefixed.

Language Variables

Language variables are automatically assigned. You can use them from the template by prefixing their name with 'L_'. in the HTML template file:

See Also