
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@pattern-lab/engine-nunjucks
Advanced tools
To install the Nunjucks PatternEngine in your edition, run npm install @pattern-lab/engine-nunjucks.
Level of Support is more or less full. Partial calls and lineage hunting are supported. Nunjucks does not support the mustache-specific syntax extensions, style modifiers and pattern parameters, because their use cases are addressed by the core Nunjucks feature set. Pattern Lab's listitems feature is still written in the mustache syntax.
To add custom filters or make customizations to the nunjucks instance, add the following to patternlab-config.json:
{
...
"engines": {
"nunjucks": {
"extend": [
"nunjucks-extensions/*.js"
]
}
}
}
...or use the default file name: patternlab-nunjucks-config.js (in the root of your Pattern Lab project).
Each file providing extensions should export a function with the Nunjucks environment as parameter.
module.exports = function (env) {
[YOUR CUSTOM CODE HERE]
};
Example: patternlab-nunjucks-config.js file that uses lodash and adds three custom filters.
var _shuffle = require('lodash/shuffle'),
_take = require('lodash/take');
exports = module.exports = function (env) {
env.addFilter('shorten', function (str, count) {
return str.slice(0, count || 5);
});
env.addFilter('shuffle', (arr) => {
return _shuffle(arr);
});
env.addFilter('take', (arr, number) => {
return _take(arr, number);
});
};
I have not yet figured out a way to support variables in pattern includes. I'm thinking it might be possible to use Nunjucks precompile feature to get the compiled partial name before returning it to Pattern Lab, but just a thought at this point.
FAQs
The nunjucks PatternEngine for Pattern Lab / Node
We found that @pattern-lab/engine-nunjucks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.