Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mojolicious/mojo-plugin-ejs

:construction: mojo.js plugin example
https://github.com/mojolicious/mojo-plugin-ejs

mojojs

Last synced: about 1 month ago
JSON representation

:construction: mojo.js plugin example

Awesome Lists containing this project

README

        








[![](https://github.com/mojolicious/mojo-plugin-ejs/workflows/test/badge.svg)](https://github.com/mojolicious/mojo-plugin-ejs/actions)
[![Coverage Status](https://coveralls.io/repos/github/mojolicious/mojo-plugin-ejs/badge.svg?branch=main)](https://coveralls.io/github/mojolicious/mojo-plugin-ejs?branch=main)
[![npm](https://img.shields.io/npm/v/mojo-plugin-ejs.svg)](https://www.npmjs.com/package/mojo-plugin-ejs)

A mojo.js plugin that adds support for [ejs](https://www.npmjs.com/package/ejs) templates. The code of this plugin is a
good example for learning to build new plugins, you're welcome to fork it.

```js
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.

```js
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](https://github.com/mojolicious/mojo.js/discussions), on [Matrix](https://matrix.to/#/#mojo:matrix.org), or
[IRC](https://web.libera.chat/#mojo).