Testing if a variable is set
His name is Adam. His job title is ceo. His salary is $1,000,000. He has 2 kids.
His name is Alistair. His job title is programmer. He has 3 kids. He likes ice cream.
<?php
# require the templating library
require '../source/ViewFish.php';
# first, you instantiate a ViewFish object
$T = new ViewFish\viewfish();
# set the template path
$T->set_template_path(__DIR__.'/../templates/');
$data = [
'name'=>'adam',
'salary'=>'$1,000,000',
'position'=>'ceo',
'kids'=>2
];
# load template
$template = $T->load_template("demo5");
// rendered template
echo $T->render($template,$data);
unset($data);
$data = [
'name'=>'alistair',
'position'=>'programmer',
'kids'=>3,
'likes'=>'ice cream'
];
// rendered template
echo $T->render($template,$data);
<h1>About {{$name|ucfirst}}</h1>
<p>His name is {{$name|ucfirst}}. His job title is {{$position}}. {{isset $salary}}His salary is {{$salary}}. {{/isset}} {{isset $kids}}He has {{$kids}} kids.{{/isset}} {{isset $likes}}He likes {{$likes}}.{{/isset}} </p>