{% extends "base.html" %} {% block header %} <h1>{{ title }}</h1> {% endblock %} {% block content %} <ul> {% for name, item in items %} <li>{{ name }}: {{ item }}</li> {% endfor %} </ul> {% endblock %}
“Nunjucks has allowed us to port all of our existing templates from a Django project to something that's easier to manage. By moving our templates to the client, transfer sizes are reduced and page responsiveness increases significantly. Our API supplies data, meaning we can decouple testing the front-end from testing the back-end. Nunjucks has made our app feel native.”
– Matt Basta, Firefox Marketplace team
Webmaker from the Mozilla Foundation encourages people to create. Using web technologies, you can create visually rich media with a powerful real-time tool. Using nunjucks, it was easy to collaborate on the templates and implement complex features such as localization. There haven't been any problems with performance or stability.
“Backbeam provides tools for mobile and web development. When we were planning the web developing features we needed an easy-to-use yet powerful templating engine. But almost all JavaScript templating engines lacked of important features such as template inheritance or flexibility to add custom behaviours (e.g. custom filters). Then we just saw the announcement of nunjucks on James' website. Since that moment we knew that nunjucks would be THE choice. Now we use nunjucks in many parts of our product. Users can edit HTML and email templates using nunjucks right in their browsers. We are really happy with our choice :)”
– Alberto Gimeno, founder of backbeam.io
“P'unk Avenue chose Nunjucks as the template language for the Apostrophe content management system, an open source CMS for node developers. We chose Nunjucks because of its close relationship with the Jinja and Twig languages, and also for its test coverage and robust implementation.”
– Tom Boutell, Senior Developer at P'unk Avenue
{{ foo | title }} {{ foo | join(",") }} {{ foo | replace("foo", "bar") | capitalize }}
{{ foo(1, 2, bar=3, baz=4) }} {{ bar | transform(level=2) }}
{% extends "base.html" %} {% block header %} <h3>{{ subtitle }}</h3> {% endblock %} {% block content %} <h1>{{ page.title }}</h1> <p>{{ page.content }}</p> {% endblock %}
asyncAll
从而让所有循环并行执行,
假定 lookup
过滤器是异步执行的。
<h1>Posts</h1> <ul> {% asyncAll item in items %} <li>{{ item.id | lookup }}</li> {% endall %} </ul>
这只是开胃菜而已。请查看 中问文档 了解所有强大特性!