2018-08-08 12:13:54 +02:00
|
|
|
# strapi-hook-ejs
|
2016-12-18 13:46:11 +01:00
|
|
|
|
|
|
|
[](https://www.npmjs.org/package/strapi-ejs)
|
|
|
|
[](https://www.npmjs.org/package/strapi-ejs)
|
|
|
|
[](https://david-dm.org/strapi/strapi-ejs)
|
|
|
|
[](https://travis-ci.org/strapi/strapi)
|
|
|
|
[](http://slack.strapi.io)
|
|
|
|
|
|
|
|
This built-in hook allows you to use the EJS template engine with custom options.
|
|
|
|
|
2018-08-08 12:13:54 +02:00
|
|
|
## Configuration
|
2016-12-18 14:03:08 +01:00
|
|
|
|
|
|
|
To configure your hook with custom options, you need to edit your `./config/hooks.json` file in your Strapi app.
|
|
|
|
```javascript
|
|
|
|
{
|
2018-08-08 12:13:54 +02:00
|
|
|
...
|
|
|
|
"ejs": {
|
|
|
|
"enabled": true,
|
|
|
|
"layout": "layout",
|
|
|
|
"viewExt": "ejs",
|
|
|
|
"partial": true,
|
|
|
|
"cache": false,
|
|
|
|
"debug": true
|
2016-12-18 14:03:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2018-08-08 12:13:54 +02:00
|
|
|
More information in the Koa ejs module https://github.com/koajs/ejs#settings
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Insert code in your controller to render a view.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
module.exports = {
|
|
|
|
home: async (ctx) => {
|
|
|
|
return ctx.render('home', {
|
|
|
|
title: 'My app title'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
This will render the `views/home.ejs` file and you will have access to `<%= title %>` data in your ejs file.
|
|
|
|
|
2016-12-18 14:03:08 +01:00
|
|
|
|
2016-12-18 13:46:11 +01:00
|
|
|
## Resources
|
|
|
|
|
|
|
|
- [MIT License](LICENSE.md)
|
|
|
|
|
|
|
|
## Links
|
|
|
|
|
|
|
|
- [Strapi website](http://strapi.io/)
|
|
|
|
- [Strapi community on Slack](http://slack.strapi.io)
|
|
|
|
- [Strapi news on Twitter](https://twitter.com/strapijs)
|