Nunjucks JavaScript Template Engine

Nunjucks JavaScript Template Engine

github.com

2

About this website

Nunjucks is a free and open-source, rich and powerful templating engine for JavaScript, heavily inspired by Jinja2 (a Python template engine). Developed by Mozilla (specifically by the Mozilla Foundation team) and first released in 2012, Nunjucks brings Jinja2's feature set to JavaScript, enabling server-side and client-side rendering of dynamic HTML templates. Key features: syntax: Nunjucks uses Jinja2-style delimiters: {{ }} for variable output, {% %} for statements (if, for, block, extends), {# #} for comments, and {{ }} with filters for expressions. Template inheritance: templates can extend other templates using {% extends 'base.njk' %} and override blocks defined with {% block content %}. This enables layout composition and DRY templates. Filters: over 20 built-in filters including upper, lower, capitalize, trim, default, join, sort, reverse, length, and date. Custom filters can be registered via addFilter. Tags and macros: custom tags and macros for reusable template logic. {% macro render_item(item) %} defines reusable template snippets. Include and import: include other templates ({% include 'header.njk' %}) and import macros from other files. Autoescaping: automatic HTML escaping of variables to prevent XSS. Configurable autoescaping per file extension. Asynchronous rendering: Nunjucks supports both synchronous (renderString, render) and asynchronous (renderStringAsync, renderAsync) rendering for environments that benefit from async I/O. Environment: the Nunjucks Environment object manages templates, filters, and configuration. Templates can be loaded from the filesystem, strings, or custom loaders. Internationalization. Browser and Node.js support. JavaScript. BSD-2-Clause.

Tags & Categories

Statistics

2
Views
0
Clicks
0
Like
0
Dislike

Comments

Log In to post a comment

No comments yet. Be the first!