mojo-plugin-ejs
v1.1.6
Published
Adds ejs template support to mojo.js
Downloads
19
Readme
A mojo.js plugin that adds support for ejs templates. The code of this plugin is a good example for learning to build new plugins, you're welcome to fork it.
import mojo from '@mojojs/core';
import ejsPlugin from 'mojo-plugin-ejs';
const app = mojo();
app.plugin(ejsPlugin);
// Render template "views/index.html.ejs"
app.get('/template', async ctx => {
await ctx.render({view: 'index'});
});
// Render an inline ejs template
app.get('/inline', async ctx => {
await ctx.render({inline: '<%- greeting %> World!', engine: 'ejs'}, {greeting: 'Hello'});
});
app.start();
To change the default engine for inline templates you can also set app.renderer.defaultEngine
to ejs
. Or you can
register the template engine with a completely different name.
app.plugin(ejsPlugin, {name: 'foo'});
app.renderer.defaultEngine = 'foo';
Installation
All you need is Node.js 16.0.0 (or newer).
$ npm install mojo-plugin-ejs
Support
If you have any questions the documentation might not yet answer, don't hesitate to ask in the Forum, on Matrix, or IRC.