ViewFish Templating
Loops
You can create loops in templates using the command @loop
. You must provide an argument called data
, where data is the name of the element in your $data array that itself contains an array of data. For example:
<ul>
{{@loop data=people}}
<li>{{firstname|ucwords}} {{lastname|ucwords}}</li>
{{/loop}}
</ul>
Would be called like so:
// prep the data array $args['people'] = [ ['firstname'=>'Charlie', 'lastname'=>'Bucket'], ['firstname'=>'Violet', 'lastname'=>'Beauregard'], ['firstname'=>'Veruca', 'lastname'=>'Salt'], ];// create the ViewFish object $t = new new ViewFish\viewfish('/path/to/templates/');
// load the template $template = $t->load_template('template-name.tmpl');
// render the template echo $t->render($template,$args);
You can see this in action in example 2.