Java jinja / django-like html templating

I have been looking for a framework of Java templates for a while that work like the Jinja / Django templating engine. The ones I found that seem popular are StringTemplate and FreeMarker, however none of them support "blocks" (jinja / django).

What I found is Jangod, and it works great, however there is no support at all, it is not supported by anyone and is not complete (i.e. there is no documentation).

I also used a template for Playframework templates, unfortunately, it is not compatible with the platform on which I am currently developing the application; Google Appengine

(TL; DR; Looking for a Java templating platform that is still alive, has a locked system like jinja, and can run under strict Appengine rules)

+4
source share
1 answer

Take a look at Rythm's template engine: http://rythmengine.com

The "block" function in jinja is called the "section" in Rythm. Therefore, suppose your layout template (parent template) is called main.html :

 <h1>@get("title", "default main page")</h1> <div id="left-panel">@render("leftPanel")<div> <div id="right-panel">@render("rightPanel")</div> <div id="main-content">@render()</div> <div id="footer"> @render("footer"){ @** * the content here is supplied if the child template failed * to provide it own footer implementation *@ <div class="footer">copyright 2012 ...</div> } </div> 

And here is your target template:

 @extends(main) @set(title: "My Cool Page") @section("leftPanel") { <ul class="menu"> ... </ul> } @section("rightPanel") { <div class="news"> ... </div> } @*** note no "footer" section supplied so the default content will be used **@ @*** the rest is for the main content **@ ... 

The real demo for this feature can be found at http://rythmengine.com/demo/testdefaultlayoutcontent

The full document can be found at http://www.playframework.org/modules/rythm . Although it aims at Play! Framework, most of the content is also applicable to pure rhythm engines without Play! Framework

You do not need to worry about GAE, as the demo itself works on GAE.

+1
source

All Articles