{continue}
Skips the rest of the current pass of a loop and goes on with its next row.
Syntax
{continue}
{continue 'name'}
Parameters
-
level -
Optional: which loop. The name of an enclosing tag or its
name=('items'), a level number, or a negative offset counting levels up from here. Without it, the nearest enclosing loop - past an{if}, a{case}and any other level that renders once for the row it stands in.
Description
{continue} abandons what is left of the current pass of a loop - everything of the loop's content after the tag is dropped - and the loop carries on with its next row, like PHP's continue. It is usually written inside an {if}, to skip the rows that do not qualify. The rows are untouched; that is the difference with {break}, which empties them.
Without a parameter it works on the nearest enclosing loop: the data tag, {sequence}, {while} or other loop the tag stands in, past an {if}, a {case} and any other level that renders once for the row - an {ifchanged}, a {guest}, a snippet. With a name - {continue 'orders'}, the tag's name or its name= - it reaches an outer loop: the inner loop is abandoned with the rest of the outer pass. A level number or a negative offset (-2: two levels up) picks the level by position.
Under the strict syntax check a name that no enclosing level has, or an offset past the page, is an error rather than a silent fall-back to the nearest loop; so is loop control with no loop around it. To skip rows that can be told apart by their fields alone, the where option on the loop is simpler.
Examples
Skipping rows
Rows that are out of stock are skipped; the loop goes on with the next one.
<ul>
{products}
{if $stock eq 0}{continue}{/if}
<li>{$name}: {$stock} left</li>
{/products}
</ul>
<?php
$products = [
[ 'name' => 'Kettle', 'stock' => 4 ],
[ 'name' => 'Toaster', 'stock' => 0 ],
[ 'name' => 'Teapot', 'stock' => 2 ],
[ 'name' => 'Mixer', 'stock' => 0 ],
[ 'name' => 'Grater', 'stock' => 9 ] ];
?>
- Kettle: 4 left
- Teapot: 2 left
- Grater: 9 left
Continuing an outer loop
Named, continue leaves the inner loop and the rest of the outer pass, and goes on with the next outer row.
{sequence '1..3', name='table'}
<br>Table {$table}:
{sequence '1..4', name='seat'}
{if $seat gt $table}{continue 'table'}{/if}
seat {$seat}
{/sequence}
- never reached
{/sequence}
Table 1: seat 1
Table 2: seat 1 seat 2
Table 3: seat 1 seat 2 seat 3
See also
- {break} Leaves a loop at once: the rest of the current pass is dropped and no further row follows.
- {cease} Ends a loop gracefully: the current pass finishes, and no further row follows.
- {while} Renders its content again and again for as long as a condition holds.
- {sequence} Generates a range, a list or one of 80 mathematical sequences, and iterates its values.