1

I've been looking at javascript templating frameworks for the past day, but unless I missed something I can't seem to find a single one with the functionality I need.

What I need is what twig calls "embed". Basically it works like a regular template include (accept variables and return a blob of html), only with the possibility to define custom "blocks". A block is typically reserved for template inheritance (or "extend") though, and that's a bit limiting.

So far, Nunjucks came closest. It has import, include and extends functionality, but not embed. To clarify with a simple example:

Template (grid.html):

<div class="grid">
  <div class="col1">
    {% block col1 %}
      [COL 1]
    {% endblock %}
  </div>
  <div class="col2">
    {% block col2 %}
      [COL 2]
    {% endblock %}
  </div>
</div>

Template usage with embed in other template (twig syntax):

{% embed "grid.html" %}
    {% block col1 %}
        [whatever goes in col1, could be other embeds here ...]
    {% endblock %}
    {% block col2 %}
        [whatever goes in col2, could be other embeds here ...]
    {% endblock %}
{% endembed %}

Anyone know about a javascript templating framework that can do this? Maybe Nunjucks can and I missed it? Help would be greatly appreciated, because we're doing a node.js project and twig is simply not an option :)

0 Answers0