ViewFish Templating
The else Block
You can provide alternate content when a variable is not set by adding {{else}} inside an {{isset}} block. This gives you if/else logic directly in your templates.
Syntax
{{isset $variable}}
Content shown when variable IS set.
{{else}}
Content shown when variable is NOT set.
{{/isset}}
Example
Template:
{{isset $role}}
<p>Your role: {{role|ucwords}}</p>
{{else}}
<p>You have not been assigned a role yet.</p>
{{/isset}}
PHP:
$t = new ViewFish\viewfish();
$template = $t->load_template('my-template.tmpl');
// With role set:
echo $t->render($template, ['name' => 'Alice', 'role' => 'admin']);
// Output: <p>Your role: Admin</p>
// Without role:
echo $t->render($template, ['name' => 'Bob']);
// Output: <p>You have not been assigned a role yet.</p>
The {{else}} block is optional. Without it, {{isset}} behaves exactly as before — the block is simply removed when the variable is not set.
You can see this in action in Example 7.