Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 2 KB

nunjucks.md

File metadata and controls

32 lines (24 loc) · 2 KB

Nunjucks

Eleventy Short Name File Extension NPM Package
njk .njk nunjucks

You can override a .njk file’s template engine. Read more at Changing a Template’s Rendering Engine.

Use your Nunjucks Environment

New in Eleventy v0.3.0: As an escape mechanism for advanced usage, pass in your own instance of a Nunjucks Environment using the Configuration API.

module.exports = function(eleventyConfig) {
  let Nunjucks = require("nunjucks");
  let nunjucksEnvironment = new Nunjucks.Environment(
    new Nunjucks.FileSystemLoader("_includes")
  );

  eleventyConfig.setLibrary("njk", nunjucksEnvironment);
};

Supported Features

Feature Syntax
✅ Includes {% include 'included.njk' %} looks in _includes/included.njk
✅ Extends {% extends 'base.njk' %} looks in _includes/base.njk
✅ Imports {% import 'macros.njk' %} looks in _includes/macros.njk
✅ Filters Read more about Filters
Eleventy Universal Filters {% name | filterName %} (see eleventyConfig.addFilter documentation)