Template code | Chunk output | |
---|---|---|
{!-- Any piece of the template encased in {% literal %}{% endliteral %} -- tags passes through uninterpreted by the template engine. -- -- The encasing tags are preserved so that the block will survive -- intact even after multiple passes through the engine. -- -- So, hiding the {% literal %} tags in HTML comments is recommended. -- -- NB: Literal tags may _not_ be nested. --} <h2>Inside the literal jail:</h2> <!-- {% literal %} --> <pre style="border: 2px dotted blue; background-color:lightblue;"> {$these:tags} {$will|onempty(not be processed)} {!-- comments will pass through to final output --} {% tagStack %} {% exec MY_TEMPLATE %}{% endexec %} {% loop in $list as $item %}{$item}{% onEmpty %}Empty list!{% endloop %} </pre> <!-- {% endliteral %} --> <hr/> <h2>Now let's see the same code outside the literal jail:</h2> <pre style="border: 2px dotted blue; background-color:lightblue;"> {$these:tags} {$will|onempty(not be processed)} {!-- comments will pass through to final output --} {% tagStack %} {% exec MY_TEMPLATE %}{% endexec %} {% loop in $list as $item %}{$item}{% onEmpty %}Empty list!{% endloop %} </pre> Theme theme = new Theme(); // fetch template from themes/example.chtml Chunk html = theme.makeChunk("example"); // Insert business logic here. // Normally you write a lot of html.set("this","that") calls here. StreamWriter out = getStreamWriter(); html.render( out ); ///// or, return the rendered template as a string // return html.toString(); |
|
<h2>Inside the literal jail:</h2> <!-- {% literal %} --> <pre style="border: 2px dotted blue; background-color:lightblue;"> {$these:tags} {$will|onempty(not be processed)} {!-- comments will pass through to final output --} {% tagStack %} {% exec MY_TEMPLATE %}{% endexec %} {% loop in $list as $item %}{$item}{% onEmpty %}Empty list!{% endloop %} </pre> <!-- {% endliteral %} --> <hr/> <h2>Now let's see the same code outside the literal jail:</h2> <pre style="border: 2px dotted blue; background-color:lightblue;"> tags not be processed Available tags: $now [chtml template 'MY_TEMPLATE' not found]<!-- looked in [themes/examples/MY_TEMPLATE.chtml] --> Empty list! </pre> Inside the literal jail:{$these:tags} {$will|onempty(not be processed)} {!-- comments will pass through to final output --} {% tagStack %} {% exec MY_TEMPLATE %}{% endexec %} {% loop in $list as $item %}{$item}{% onEmpty %}Empty list!{% endloop %} Now let's see the same code outside the literal jail:tags not be processed Available tags: $now [chtml template 'MY_TEMPLATE' not found] Empty list! |