4

I've been looking for a Java templating framework for a while that works like Jinja / Django's templating engine. The ones i've found that seem to be popular are StringTemplate and FreeMarker, however neither seem to support "blocks" ( jinja/django ).

What I have found is Jangod, and it works great - however, there is no support at all, it is not maintained by anyone, and is unfinished ( ie, no documentation ).

I've used Playframework's templating too, sadly it isn't compatible with the platform i'm developing an application on now; Google Appengine.

( TLDR; Looking for a Java templating framework that is still alive, has a blocks-system like jinja, and can run under the strict rules of Appengine )

Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
Philipp Gayret
  • 4,870
  • 1
  • 28
  • 34
  • Possible duplicate: http://stackoverflow.com/questions/490390/jsp-template-inheritance – Peter Knego Sep 02 '12 at 18:51
  • 1
    Chunk is a java template engine with syntax that is very similar to jinja/django. Chunk now runs on GAE: http://chunk-docs.appspot.com/ – Tom McClure Dec 31 '14 at 16:43

1 Answers1

1

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

The "block" feature in jinja is called "section" in Rythm. So suppose your layout template (parent template) 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's 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 **@
...

A real demo for this feature could be found at http://rythmengine.com/demo/testdefaultlayoutcontent

A comprehensive document could be found at http://www.playframework.org/modules/rythm. Though it's targeted to Play!Framework, most of the content also apply to pure rythm engine without Play!Framework.

You don't need to worry about GAE coz the demo itself is running on GAE.

Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
  • Seeing all the features, it looks really good - especially the cache utilities, just to be sure; does it support nested "sections"? – Philipp Gayret Sep 03 '12 at 11:39
  • nested sections is supported. "ToString" feature has a problem on GAE on the version deployed. I have a fix already. Source code of the entire site could be found at http://github.com/greenlaw110/rythm-website/. The documentation could be found at http://www.playframework.org/modules/rythm – Gelin Luo Sep 03 '12 at 19:50