Development Wiki

Template.assign block vars

From phpBB Development Wiki

Revision as of 22:06, 22 September 2008 by Highway of life (Talk | contribs)

template::assign_block_vars –– Assign key variable pairs from an array to a specified block.


  1. bool template:: assign_block_vars (String $blockname, array $vararray )

The Template.assign_var and Template.assign_vars method doesn't allow you to create loops inside a template, in order to achieve this you'll have to user the assign_block_vars method of the template object.

Note: The means of transporting data to the template is the use of template variables.. By convention, template variable names are always all-uppercase where block names are always all-lowercase. Variables output to the user are enclosed in curly braces, and are formatted in the following way: {blockname.L_VARIABLE_NAME}.


Parameter Usage
blockname The name of the block in which the variables will be assigned.
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

Example of a block in a HTML template:

BEGIN somerow -->
END somerow -->

Example php controller to assign this block:

// Loop twice
for ($i 0$i 2$i++)
$template->assign_block_vars('somerow', array(
'VAR1' => "Just a string with the value of \$i: $i",
'VAR2' => ($i 4),

See Also