Template code | Chunk output | |
---|---|---|
{!-- Supply a default from the template, to output when -- tag is not defined. Everything after the colon : -- becomes the tag value (NB: null and undefined are -- NOT the same - see example 4 below). --} <p>Hello {$name:there}! You're our grand prize winner!</p> 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(); |
![]() |
<p>Hello there! You're our grand prize winner!</p> Hello there! You're our grand prize winner! |
Template code | Chunk output | |
---|---|---|
{!-- Default to the empty string, no tag preservation. --} <div>{$error_message:}</div> 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(); |
![]() |
<div></div> |
Template code | Chunk output | |
---|---|---|
{!-- Supply a default from the template, to output when -- tag is: (A) only whitespace, or (B) is the empty string, -- or (C) is not defined at all. -- -- The pipe character | marks the start of a tag output filter. --} Hello {$name|onempty(there)}! You're our grand prize winner! 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(); |
![]() |
Hello there! You're our grand prize winner!
Hello there! You're our grand prize winner!
|
Template code | Chunk output | |
---|---|---|
{!-- IMPORTANT!! The following two calls are equivalent: -- -- c.set("tag",null); -- c.set("tag",""); -- -- Chunk's null-trapping turns null into the empty string. -- Furthermore, the empty string is considered "defined" when -- rendering the template. -- -- So, if you *want* a default value to display (eg {$tag:default} ), -- don't use null!! Instead, make sure a tag is undefined like so: -- -- c.setOrDelete("tag",null); -- // or... -- c.unset("tag"); -- // or just don't call .set() at all! -- // in the example below, "tag" will be undefined except on Wed. -- if (isWednesday) { -- c.set("tag","hump day"); -- } --} <div>{$tag:default}</div> 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(); |
![]() |
<div>default</div> default
|