Hsoy Templates is a client- and server- side templating system for web and Java.
Based on Google Closure Templates with adding HAML syntax.
Licensed under Apache 2 license.
This template:
!!! namespace tests
/
Greets a person using "Hello" by default.
@param name The name of the person.
@param? greetingWord Optional greeting word to use instead of "Hello".
#greeting
%h1
A Greeting
{if not $greetingWord}
.default
Hello {$name}!
{else}
.special
{$greetingWord} {$name}!
{/if}
will generate for {name: 'John'}
:
<h1>A Greeting</h2>
<div class="default">
Hello John!
</div>
and for {name: 'Ivan', greetingWord: 'Privet'}
:
<h1>A Greeting</h2>
<div class="special">
Privet Ivan!
</div>
{}
for commands.{lb}
and {rb}
for left- and right brackets if you need to put them into result html{if ...} ... {/if}
If you need help for HAML syntax - see http://haml.info/
For variable use just a {$variable}
(notice that $
is placed inside {}
)
{<expression>}
{print <expression>}
You can post process print
Option | Description |
---|---|
noAutoescape | turns off autoescaping |
escapeHtml | manually HTML-escape the output |
escapeUri | escape the output so that it can be inserted into a URI parameter |
escapeJsString | escape the output so that it can be inserted into a JavaScript string |
truncate: |
truncate a string to a maximum length n with trailing ellipsis, optional ',false' to truncate without an ellipsis. |
changeNewlineToBr | change newlines (\n, \r, or \r\n) to <br>s. |
{<expression> |noAutoescape}
{print <expression> |noAutoescape}
{<expression> |truncate:10,false}
{if <expression>} .... {/if}
{if <expression>}
.hello
Hello {$variable}!
{/if}
{if <expression>}
Hello
{elseif <expression>}
Bueno
{else}
%span.error hey?!
{/if}
where <expression>
could be:
{if $variable}
{if $variable > 5}
{if $variable == $anotherVariable}
{if not $variable}
{if $variable and $anotherVariable}
{foreach <var> in <array>}
...
{ifempty}
...
{/foreach}
The iterator var
is a local variable that is defined only in the block. Within
the block, you can also use three built-in functions that only take foreach variables as arguments:
isFirst($var)
returns true only on the first iteration.isLast($var)
returns true only on the last iteration.index($var)
returns the current index in the list. List indices are 0-based.TO DO
TO DO
<dependency>
<groupId>com.the6hours</groupId>
<artifactId>hsoy-templates</artifactId>
<version>0.4</version>
</dependency>
<repositories>
<repository>
<id>the6hours-release</id>
<url>http://maven.the6hours.com/release</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>