setGlobalVariable()

setGlobalVariable() – Sets a global variable value.

Synopsis

require_once 'HTML/Template/Sigma.php';

void HTML_Template_Sigma::setGlobalVariable ( mixed $variable , string $value = '' )

Description

Sets a global variable value. Global variables are "special": they do not get cleared after substitution and do not make blocks not empty if substituted.

Parameter

mixed $variable

variable name or array ('varname'=>'value')

string $value

variable value if $variable is not an array

Throws

throws no exceptions thrown

Note

This function can not be called statically.

setCurrentBlock() (Previous) setOption() (Next)
Last updated: Tue, 02 Jun 2009 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by: shayne.oneill@gmail.com
This is a really good function to know about as it solves a common conundrum.

Oftentimes in a list form you'll get a situation where you have something like (All follows in pseudocode/pseudohtml)

[-- BEGIN block --]
{item1} {item2} {currency}{price}
[-- END block --]
{currency}{total}

Now, you'd itterate that block by doing something like
foreach ($items as $item) {
$template->setvariable(array('item1'=>'$item[item1],'item2'=>$item[item2],'currency'=>'$','price'=>$item[price]))
$template->parseBlock('block')
}

Now if you do a setvariable to get the currency in the currency/total, it'll also mark a new block and you end up with an empty block line.

HOWEVER if you use the setGlobalVariable, it wont unempty the block, thus leaving the table as it should