Community Documentation

v3 Knowledgebase

Assign variables to the template

Hello, in this article we will talk about displaying basic dynamic information.

In phpfox we have controllers and blocks, these are split each in .class.php files for high level logic and .html.php for the presentation.
If we want to display something from the logic into the presentation we use the template object, for example:
/* This can be any string */
$sUsername 'MyUsername';

/* This is how we interact with the template from the php end */
'myVariable' => $sUsername

At this point the php end has created a variable in the template that we can use like this:
Hello {$myVariable}!

And that will output "Hello MyUsername". Notice how the assign() function takes an array, we can add more assignments as entries in that array if we want.

Now lets try a simple array and a simple action on that array from the presentation end:
$aArray = array('1''2''3''4');

$this->template()->assign(array('anArray' => $aArray)); 

And from the .html.php file
I can count! {foreach from=$anArray item=sNumber} {$sNumber} {/foreach}