wadelau.github.io

Hanjst

What is Hanjst and Why

What is Hanjst?

Han JavaScript Template Language and Engine.

Hanjst Logo

Hanjst is a template language aiming at descibing a page of Web contents.

Hanjst is also a template engine which parses the pages written in Hanjst template language.

Han is the surname of my wife, and one of the given names of my daughter and son.

Han is also Chinese in Pinyin, Hànrén (汉人).

To design this template language and engine from the perspective of a linguist, the procedural expression of grammar and semantics is realized by the engineer's thinking.

This is the Hanjst template language and engine from the jointly collaboration of linguists and computer engineers.

Hanjst is intentionally designed to stop further “Reinventing the wheel” for HTML template engines though it sounds ridiculous.

汉吉斯特” in Chinese.


Why Template?

A template engine enables us to use static template files in an application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an final HTML.

MVC separation, see ASP.NET MVC Pattern .

Clear and clean codes, see Why would I use Smarty .

Why You Should be Using Templating Engine


Why Hanjst?

It is easy to create another new template language and engine with JavaScript. therefore, there are too many JavaScript-based templates and corresponding engines for HTML.

Frankly speaking, the basic reason is that it is a simple and easy piece of work to make replaces work with a template and its engine which is designed to parse the template sentences into final representations.

To be complicated, the template language is a new design of expression language. The difficulty of designing a language is beyond imagination. The language must meet the needs of daily usage and high-frequency communication. The first thing that language designers should consider is that the template language is universally accepted and widely used, so that the language has vitality. Undoubtedly, succinct and ideographic richness are important and priority considerations.

Unfortunately, there is no state of art work for this job prior to Hanjst.

Mindmap of templates engines

Through the analysis of the brain map, we found that there are still two problems in this field that have not been solved, or are not well solved: 1) On the server side, is there a template language and engine that can be implemented cross-development languages? 2) Client/browser terminal, is there a template language and engine that can do without script tags?

What we expect from a client-side template, i.e., JavaScript-based template, are three keys points:

Applying these criteria to all of exist JavaScript-based templates, however, it is hard to find one which meets all of these requirements.

Code snippets of a JavaScript-based template:

<script id="template" type="x-tmpl-mustache">
Hello `{`{ name `}`}!
</script>

Demerits or dislikes we find in these lines are:

As fans of Smarty, we would like to design and implement a whole newly-created JavaScript-based template language to cover all scenarios where Smarty has achieved.

However, it is NOT Smarty in JavaScript, which has been implemented and found in -GitHub, e.g. JSmarty or SmartyJS. What’s more, both of them has not been enforced to act as powerful as that of Smarty in server-side.

From the point of view of GWA2, we would need a template engine to work with all back-end programming languages, i.e., PHP, Java, Perl, Python, Aspx and so on.

That’s to say, we cannot use Smarty for GWA2 in PHP and Velocity for GWA2 in Java.

There does have a few of template languages and engines which meet the desirable requirements, but most of them are proprietary software sets and cannot be used in open source as GWA2.

Therefore, the searching space left for us is limited and an encouraged option is to create a new template language and engine.

Combining all those considerations and bearing expected features and functions in mind, the invented template and its engine, so-called Hanjst, has mertis as:

All in one, we believe that Hanjst would be the final JavaScript-based template language, and it has all functions which needed in client-side run-time. Also, any further "reinvent of the wheel" in this field would be meaningless.

We have integrated Smarty in GWA2PHP and it works very well before. When we have developed GWA2Java, we find that Smarty fans on the Internet had moved Smarty to the Java version, Smarty4J, so we also integrated Smarty4J consequently.

Unfortunately, Smarty4J is a version of about 7-8 years ago, and has not been updated since then, also it is only compatible with the syntax of Smarty 2, which heavily limits the further development of GWA2Java.

So we have committed to make this switch happen. Hanjst will be our default template engine in GWA2 ecosystem since then.


  1. Hanjst Homepage
  2. Hanjst first release blog.
  3. GWA2’s default template switch from Smarty to Hanjst.

Back to top

PreviousNext

Back to Up