Documente Academic
Documente Profesional
Documente Cultură
To use it, simply copy the Python file or the JavaScript file into your project. Neither
has any external dependencies.
Since there are over one bajillion template languages for Python alone, it deserves
some explanation. But first here are some examples.
Simple example
>>> import jsontemplate
>>> jsontemplate.expand('Hello {name}', {'name': 'world'})
'Hello world'
This Python example should look familiar to many people.* The JavaScript version
is a straightforward translation of this API.
Full Example
To read this example, keep in mind the following:
A variable can be substituted by surrounding its name with curly braces: {}
Template "directives" start with a period: .
In place of for loops and if statements, the basic idea is that the
template declaressections and repeated sections. The sections are named
after keys in the JSON data dictionary. The presence or absence of the keys
in the JSON dictionary implicitly determines if and how many times a
section is expanded.
If a JSON dictionary key is missing or empty ([], {}, or null), then
the {.or} section is expanded.
These few constructs are surprisingly powerful.
The following example uses most of the language, but not all.
A template string ...
{# This is a comment and will be removed from the output.}
{.section songs}
<h2>Songs in '{playlist-name}'</h2>
<table width="100%">
{.repeated section @}
<tr>
<td><a href="{url-base|htmltag}{url|htmltag}">Play</a>
<td><i>{title}</i></td>
<td>{artist}</td>
</tr>
{.end}
</table>
{.or}
<p><em>(No page content matches)</em></p>
{.end}
Grayceon
Play
Thou