{content}
Keeps a piece of template under a name instead of printing it, for a later {name} to render.
Syntax
{content 'name'} ... {/content}
{content 'name', 'text'}
{content} ... {/content 'name'}
Parameters
-
name -
The name the content is kept under;
{name}or{content:name}renders it,content='name'on another tag uses it as that tag's content. Not the name of a built-in or application tag. -
text - Optional, when there is no content: the content as a quoted text, or a field whose value is kept as text.
Description
{content 'name'} ... {/content} stores its content under that name and prints nothing. The content is kept as template source, unrendered: fields and tags in it are resolved each time it is used, with the values of that moment and of that place. Written once, it can be rendered many times - {name} or {content:name} - or handed to another tag as its body with content='name', so one row template serves several loops.
With the name on the closing tag instead - {content} ... {/content 'name'} - the content is rendered first, where it stands, and the finished text is kept: a snapshot that no longer changes with the variables.
Without content, a second parameter gives the text: {content 'hi', 'Hello'}. A field there - {content 'c', $text} - is a value, and like every value it stays text when the content is rendered: braces in it never run as tags.
Stored content is also what the else=, null= and notOk= options of every tag put in place of a level that came up empty - see {false} and {null}. Under the strict syntax check a {content} without a name, or with the name of a built-in or application tag, is an error.
Examples
One row template, two lists
The stored content is rendered as the body of two loops, with the fields of each row.
{content 'contentRow'}<li><strong>{$name}</strong> - {$role}</li>{/content}
<h4>Staff</h4>
<ul>{contentStaff content='contentRow'}{/contentStaff}</ul>
<h4>Volunteers</h4>
<ul>{contentHelpers}{contentRow}{/contentHelpers}</ul>
<?php
$contentStaff = [ [ 'name' => 'Ann', 'role' => 'manager' ], [ 'name' => 'Bo', 'role' => 'cook' ] ];
$contentHelpers = [ [ 'name' => 'Cas', 'role' => 'driver' ] ];
?>
Staff
- Ann - manager
- Bo - cook
Volunteers
- Cas - driver
Source or snapshot
Named on the opening tag the content renders with today's values; named on the closing tag it is rendered once and kept.
{set $price = 10}
{content 'contentLive'}the price is {$price}{/content}
{content}the price was {$price}{/content 'contentFixed'}
{set $price = 12}
<p>Live: {contentLive}</p>
<p>Snapshot: {contentFixed}</p>
Live: the price is 12
Snapshot: the price was 10
See also
- {data} Turns its content - JSON, XML, YAML, CSV, a list or a range - into a named data set for a later tag to iterate.
- {bool} Reduces its content or a value to TRUE or FALSE and keeps it under a name, for a later {name} to test.
- {null} The constant NULL: its content is dropped, the @else@ part too, and a null= option fires.
- {false} The constant FALSE: its content is skipped and its @else@ part renders instead.