Development Templating in Nunjucks
Using Nunjucks in Jinja2 templates
Add the following import:
from jinja2 import ChainableUndefined
Then add the following configuration change:
jinja_env.undefined = ChainableUndefined
How to set up Nunjucks
In your Nunjucks configuration you’ll need to add
node_modules/@ons/design-system/layout to your search paths.
You can get all components and templates from a zip file that is created with each . You need to create a script that gets the zip and unpacks the contents. For development, the script could run manually, and the folders added to a
.gitignore file. In production, it would need to be run within a build process as part of a continuous integration task.
If you are using Jinja, your script will need to copy the
layout folders from the unzipped download into your
templates folder. This is where Jinja looks for templates as multiple search paths cannot be specified.
The zipped templates have already got the content delivery network (CDN) release version and paths set based on the version of the templates you have downloaded.
How to use Nunjucks with components
Each component contains examples and any context-specific variants. You can copy the Nunjucks code directly from the examples.