Hsoy Templates is a client- and server- side templating system for web and Java.

Based on Google Closure Templates with adding HAML syntax.


  • One template for both client and server
  • HAML syntax
  • Fast
    • compiled into Java, to run on Server Side
    • compiled into JavaScript, to run in Browser (or NodeJs)
  • Rich command system (based on Google Closure Templates)


Licensed under Apache 2 license.

Template Structure

Hsoy Template Example

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".
    A Greeting
  {if not $greetingWord}
      Hello {$name}!
      {$greetingWord} {$name}!

will generate for {name: 'John'}:

<h1>A Greeting</h2>
<div class="default">
 Hello John!

and for {name: 'Ivan', greetingWord: 'Privet'}:

<h1>A Greeting</h2>
<div class="special">
 Privet Ivan!


General syntax

  • Hsoy Templates uses braces {} for commands.
  • use commands {lb} and {rb} for left- and right brackets if you need to put them into result html
  • open-close block commands: {if ...} ... {/if}
  • use indentation for multi line block commands
  • based on Google Closure Templates, so you can also use docs from here:

If you need help for HAML syntax - see

Print value

For variable use just a {$variable} (notice that $ is placed inside {})

General syntax:

{print <expression>}

Print Options

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:[,false] 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 {$variable}!

{if <expression>}
{elseif <expression>}
  %span.error hey?!

where <expression> could be:

  • {if $variable}
  • {if $variable > 5}
  • {if $variable == $anotherVariable}
  • {if not $variable}
  • {if $variable and $anotherVariable}


{foreach <var> in <array>}

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.

JavaScript Usage


Java Usage




  • you need extra repository: