Template.assign block vars

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

Description
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.
 * 1) bool template:: assign_block_vars (String $blockname, array $vararray )


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

Return Values
Returns true

Example #1 Single block
Example of a block in a HTML template:

 {somerow.VAR1} {somerow.VAR2} 

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

Example #2 Nested blocks
Example of PHP Controller assigning the values to the nested blocks: // setup an example multi-dimensional array... $item_ary = array(	'food'		=> array( 'banana', 'apple', 'pie', 'ice-cream', ),

'animal'	=> array(		'Horse',		'Dog',		'Cat',	), );

foreach ($item_ary as $category => $item_ary) {	// categories in this example are "food" and "animal" $template->assign_block_vars('block1', array( 'CATEGORY'	=> $category, ));

// each item within the category is assigned to the second block. foreach ($item_ary as $key => $item) {		$template->assign_block_vars('block1.block2', array( 'ITEM'		=> $item, 'ITEM_NUM'	=> $key + 1, ));	} }

Example of nested blocks in an HTML template:

 {block1.CATEGORY}   {block1.block2.ITEM_NUM}: {block1.block2.ITEM}   