Basic Syntax

Hello World

Let’s make a start with “Hello World”. (eg08092010)

Hello {$user}!

<div id="Hanjstjsondata">
	{"user":"World", "copyright_year": 2019}
<script type="text/javascript" src="Hanjst.js"></script>

Hanjst will parse this template and generate a final representation of the HTML page as below.

Hello World!


Inside the box of Hanjst, it reads template data from the element identified by “Hanjstjsondata”, and reads template sentence from the element of BODY.

If these steps work well, Hanjst tries to load template data into current JavaScript run-time by introducing each key of JSON data as a variable. And Hanjst find each pair of lines enclosed with {…}.

When all of these are ready, computing and replacements are going on each block of codes step by step.


Hanjst template variables start with the $dollar sign as default. They can contain numbers, letters and underscores, just like a variable in JavaScript. We can reference arrays by index numerically or non-numerically, and also reference object properties and methods.

Some other template languages also defined a variable in this way, e.g. PHP or Smarty.




display a variable

display a variable after its addtion


display the 2nd element of a zero-indexed array


display the “bar” key value of an array



same as $foo[‘bar’]




display a multiple dimension array




define a variable



add 1, or 2 to variable i



define an array and set an element

{$myList=new Object()}


define an object and set a key


Hanjst functions are all functions of JavaScript. Reversely, all JavaScript functions and objects are all accessible to the current Hanjst.


display the return of function “foo”


display the return of function “foo”, with a parameter “bar”

Built-in Functions

As stated above, all built-in functions in JavaScript are accessible in Hanjst template run-time, so there too many to iterate the list.

See MDN JavaScript Docs online for detailed instructions and references.

Custom Functions

Besides of so many built-in JavaScript functions, developers are encouraged to make custom objects, classes or functions for specific usages.

An example is attached below.

Define the custom function in JavaScript:

function foo(x, y){
	return x = x + y;

Call it in HTML written in Hanjst template language:

<!-- define variables -->
<!-- display a custom function result -->
{$foo($a, $b)}
<!-- output: 8 -->


Comments in Hanjst have two parts. For JavaScript part,

//-- this is a line comment
 * these are block comment

For HTML part,

<!-- this is a line comment in html -->

  1. Mozilla Developer Network, Web Docs, JavaScript
  2. Hanjst Demo Page

Back to Top


Back to Up