The Unless Statement
Show content when a variable is not set — the inverse of isset.
The {{unless}} Statement
Show content when a variable is not set — the inverse of {{isset}}.
Product 1 — discount + shipping note:
Wireless Headphones
🎉 Discount applied! You save $20.00. Pay only $59.99.
📦 Free 2-day shipping for Prime members!
Product 2 — no discount, in stock:
USB-C Charging Cable
No discount available. Regular price: $12.99
Standard shipping applies.
Product 3 — out of stock, no discount:
Limited Edition Sneakers
No discount available. Regular price: $249.99
Out of stock. Check back later.
Standard shipping applies.
<?php
# require the templating library
require '../vendors/ViewFish/viewfish.php';
# instantiate a ViewFish object
$T = new ViewFish\viewfish();
# set the template path
$T->set_template_path(__DIR__.'/../templates/');
# load the template
$template = $T->load_template("demo10");
# Product with discount and in stock
$product1 = [
'title' => 'wireless headphones',
'price' => '79.99',
'discount' => '20.00',
'final_price' => '59.99',
'in_stock' => '1',
'shipping_note' => 'Free 2-day shipping for Prime members!',
];
# Product with no discount, in stock
$product2 = [
'title' => 'USB-C charging cable',
'price' => '12.99',
'in_stock' => '1',
];
# Product out of stock, no discount
$product3 = [
'title' => 'limited edition sneakers',
'price' => '249.99',
];
echo "<h4>The <code>{{unless}}</code> Statement</h4>";
echo "<p>Show content when a variable is <em>not</em> set — the inverse of <code>{{isset}}</code>.</p><hr>";
echo "<h5>Product 1 — discount + shipping note:</h5>";
echo $T->render($template, $product1);
echo "<h5>Product 2 — no discount, in stock:</h5>";
echo $T->render($template, $product2);
echo "<h5>Product 3 — out of stock, no discount:</h5>";
echo $T->render($template, $product3);
<div class="card mb-3">
<div class="card-body">
<h5>{{title|ucwords}}</h5>
{{unless $discount}}
<p class="text-muted">No discount available. Regular price: ${{price}}</p>
{{else}}
<p class="text-success">🎉 Discount applied! You save ${{discount}}. Pay only ${{final_price}}.</p>
{{/unless}}
{{unless $in_stock}}
<p class="text-danger"><strong>Out of stock.</strong> Check back later.</p>
{{/unless}}
{{unless $shipping_note}}
<p>Standard shipping applies.</p>
{{else}}
<p>📦 {{shipping_note}}</p>
{{/unless}}
</div>
</div>