Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

mojo-plugin-nunjucks

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mojo-plugin-nunjucks

Adds nunjucks template support to mojo.js

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

Coverage Status npm

A mojo.js plugin that adds support for nunjucks templates. The code of this plugin is a good example for learning to build new plugins with TypeScript, you're welcome to fork it.

import mojo from '@mojojs/core';
import nunjucksPlugin from 'mojo-plugin-nunjucks';

const app = mojo();
app.plugin(nunjucksPlugin);

// Render template "views/index.html.njk"
app.get('/template', async ctx => {
  await ctx.render({view: 'index'});
});

// Render an inline nunjucks template
app.get('/inline', async ctx => {
  await ctx.render({inline: '{{ greeting }} World!', engine: 'njk'}, {greeting: 'Hello'});
});

app.start();

To change the default engine for inline templates you can also set app.renderer.defaultEngine to njk. Or you can register the template engine with a completely different name.

app.plugin(nunjucksPlugin, {name: 'foo'});
app.renderer.defaultEngine = 'foo';

You can also extend the environment with custom filters and tags.

app.renderer.engines.njk.env.addFilter('hello', name => {
  return `hello ${name}`;
});

Installation

All you need is Node.js 16.0.0 (or newer).

$ npm install mojo-plugin-nunjucks

Support

If you have any questions the documentation might not yet answer, don't hesitate to ask in the Forum, on Matrix, or IRC.

Keywords

mojojs

FAQs

Package last updated on 20 Oct 2023

Did you know?

Socket

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.

Install

Related posts