Template code | Chunk output | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
{#example_1} {!-- Starting in Chunk 2.0, you can now loop over the -- attributes of an associative array (aka a Map/Object) -- just as you can in, say, PHP. -- -- {.loop in $object as $key:$value} --} <style> .properties th { text-align: left; background-color: #dedede; } .properties td { background-color: whitesmoke; } .properties td, .properties th { padding: 2px 5px 2px 10px; border-bottom: 1px solid #888888; } </style> <h2>Team Properties</h2> <table class="properties" cellspacing="0" cellpadding="0" border="0"> <tr> <th>Property</th> <th>Value</th> </tr> {.loop in $team as $attr:$value} <tr> <td>{$attr}</td> <td>{$value}</td> </tr> {/loop} </table> {#} import net.minidev.json.JSONValue; //... Theme theme = new Theme("examples"); // Fetch template from this file: themes/examples/loopobject.chtml // Inside that file there is a template "snippet" named #example_1 Chunk html = theme.makeChunk("loopobject#example_1"); // Sometimes a chtml snippet is a handy place to store some data. String jsonTeamData = theme.fetch("loopobject#example_2"); html.set("team", JSONValue.parse(jsonTeamData) ); html.render( out ); |
![]() |
<style> .properties th { text-align: left; background-color: #dedede; } .properties td { background-color: whitesmoke; } .properties td, .properties th { padding: 2px 5px 2px 10px; border-bottom: 1px solid #888888; } </style> <h2>Team Properties</h2> <table class="properties" cellspacing="0" cellpadding="0" border="0"> <tr> <th>Property</th> <th>Value</th> </tr> <tr> <td>Name</td> <td>Boston Red Sox</td> </tr> <tr> <td>Sport</td> <td>Baseball</td> </tr> <tr> <td>2012 Win-Loss Record</td> <td>69-93</td> </tr> <tr> <td>2013 Win-Loss Record</td> <td>97-65</td> </tr> </table> Team Properties
|
Template code | Chunk output | |
---|---|---|
![]() |
{ Name: "Boston Red Sox", Sport: "Baseball", "2012 Win-Loss Record": "69-93", "2013 Win-Loss Record": "97-65", }
{ Name: "Boston Red Sox",
Sport: "Baseball",
"2012 Win-Loss Record": "69-93",
"2013 Win-Loss Record": "97-65",
}
|