我一直在寻找过去一天的javascript模板框架,但除非我错过了一些东西,否则我似乎无法找到具有我需要的功能的单一框架 .

我需要的是twig所谓的“嵌入” . 基本上它就像常规模板包含(接受变量并返回一个hb blob),只有定义自定义“块”的可能性 . 块通常保留用于模板继承(或“扩展”),但这有点限制 .

到目前为止,Nunjucks最接近 . 它具有导入,包含和扩展功能,但不嵌入 . 用一个简单的例子来澄清:

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 %}

任何人都知道一个javascript模板框架,可以做到这一点?也许Nunjucks可以而且我错过了吗?非常感谢帮助,因为我们正在做一个node.js项目而twig根本不是一个选项:)