Chunk Templates provides support for this type of thing with {% exec %}
like so:
base_template.chtml
<html>
<head>
</head>
<body>
{$body}
</body>
</html>
widget_detail.chtml
{% exec base_template %}
{$body=}
...
{=}
{% endexec %}
Here's a more interesting example where the base template provides some defaults that you can override from the servlet or in an exec:
base_template2.chtml
<html>
<head>
<title>{$page_title:Widget Emporium}</title>
</head>
<body>
{$top_nav:.include top_nav}
{$left_nav:.include left_nav}
{$body}
{$footer:.include footer}
</body>
</html>
top_nav.chtml
<div class="top_nav">
...
</div>
left_nav.chtml
<div class="left_nav">
...
<div>
footer.chtml
<div class="footer">
...
<div>
special_page.chtml - suppress all nav and use alternate footer
{% exec base_template2 %}
{$body=}
...
{=}
{$page_title = Special Page}
{$top_nav=}{=}
{$left_nav=}{=}
{$footer=}{% include special_footer %}{=}
{% endexec %}
exec also supports json and xml for tag value assignment.
For simpler things, Chunk syntax is quite similar to Django/jinja2. Filters are applied with pipes in the same way: {$tag|filter}
and Chunk tags are written as {$tag}
or {% $tag %}
rather than {{ tag }}
but you get used to it pretty quickly.
If-else branching in particular should look very familiar to anyone coming from Django:
{% if (...) %}
true-case
{% else %}
false-case
{% endif %}
Disclaimer: I am the author/maintainer for Chunk. The project is open-source and on GitHub.
base.html
and at the place where content is not same for all files, you say{{block body}}
. Then, in another file, saylogin.html
, if you're using template inheritance, you only need to say{extends base.html}
and then{{start bodyblock}} Your new content {{end bodyblock}}
. This will render the static as well as dynamic content. You can invoke any file from another file. – Ranveer Oct 22 '14 at 12:18