Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mojolicious/mojo-plugin-ejs
- Owner: mojolicious
- License: mit
- Created: 2022-06-05T12:40:44.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-24T11:59:41.000Z (about 2 months ago)
- Last Synced: 2024-09-29T07:22:35.770Z (about 1 month ago)
- Topics: mojojs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mojo-plugin-ejs
- Size: 28.3 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Authors: AUTHORS
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).