Template code Chunk output
{!-- This example showcases exec macros, nestable conditionals and loops.
  -- The template to execute can be inline, defined in the optional
  -- {.body}...{/body} section, or you can execute a template snippet
  -- from anywhere in your theme.
  --
  -- {.exec [template-name|@inline] [xml|json|json-strict|default]}
  --   PARAMS...
  --
  --    {.body}
  --      ...
  --    {/body}
  -- {/exec}
  --
  -- You must add the json-smart library jar to your classpath if you
  -- wish to use json or json-strict parameter formatting.
  --}
{.exec @inline json}

 {
  name: "Jim and Della",
  assets: [{name:"Hair",value:"195"},
           {name:"Watch",value:"145"}]
 }

 {.body}
<div>

 <h1>{$name}</h1>
 
 {.if ($assets) }
 <h2>Assets</h2>
 <ul>
  {.loop in $assets as $asset}
  <li>{$asset.name} - ${$asset.value|sprintf(%.2f)}</li>
  {/loop}
 </ul>
 {/if}
 
</div>
 {/body}

{/exec}
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>

 <h1>Jim and Della</h1>
 
 <h2>Assets</h2>
 <ul>
  <li>Hair - $195.00</li>
  <li>Watch - $145.00</li>
 </ul>
 
</div>

Jim and Della

Assets

  • Hair - $195.00
  • Watch - $145.00
Template code Chunk output
{!-- The difference between {.include} and {.exec}...{/exec}
  --}
<h2>Include:</h2>
{.include #example_3}

<hr/>

<h2>Exec:</h2>
{.exec #example_3 json}
 {name:"Armstrong",
  message:"Your turn to buy beer."}
{/exec}
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>Include:</h2>
<div>
 Earth to {$name}.  Come in, {$name}.
</div>


<hr/>

<h2>Exec:</h2>
<div>
 Earth to Armstrong.  Come in, Armstrong.

 <p>Your turn to buy beer.</p>
</div>

Include:

Earth to {$name}. Come in, {$name}.

Exec:

Earth to Armstrong. Come in, Armstrong.

Your turn to buy beer.

Template code Chunk output
{#example_3}
<div>
 Earth to {$name}.  Come in, {$name}.
 {.if ($message) }

 <p>{$message}</p>
 {/if}
</div>
{#}
//...
<div>
 Earth to {$name}.  Come in, {$name}.
</div>

Earth to {$name}. Come in, {$name}.
Template code Chunk output
{!--
  --    {.exec [template] xml}     (tag values passed via XML)
  --}
{.exec #example_3 xml}
<values>
 <name>XML</name>
 <message>Oh, XML, you're so bloated.</message>
</values>
{/exec}
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>
 Earth to XML.  Come in, XML.

 <p>Oh, XML, you're so bloated.</p>
</div>

Earth to XML. Come in, XML.

Oh, XML, you're so bloated.

Template code Chunk output
{!--
  --    {.exec [template]}    (default arg-passing format)
  --}
{.exec #example_3}
 {$name = Apollo}
{/exec}
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>
 Earth to Apollo.  Come in, Apollo.
</div>

Earth to Apollo. Come in, Apollo.
Template code Chunk output
{!--
  --    {.exec [template]}    (default arg format, block tag variation)
  --}
{.exec #example_3}
 {$name = Apollo}
 {$message=}{.include lorem_ipsum}{=}
{/exec}
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>
 Earth to Apollo.  Come in, Apollo.

 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>

Earth to Apollo. Come in, Apollo.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Template code Chunk output
{!-- add examples with xml attributes, nested parameter data --}
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();