phpBB

Development Wiki

Template.assign block vars

From phpBB Development Wiki

Revision as of 21:59, 22 September 2008 by Erik frèrejean (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

Description

  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}.

Parameters

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

Examples

Example #1

Example of a block in a HTML template:

<div>
<!-- 
BEGIN somerow -->
   <
ul>
      <
li>{somerow.VAR1}</li>
      <
li>{somerow.VAR2}</li>
   </
ul>
<!-- 
END somerow -->
</
div>

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),
   ));
}