如何在 Strapi 中使用 EJS
How to use EJS in Strapi
官方文档试过了,还是不行
https://github.com/strapi/strapi-docs/blob/master/files/views.md
这里是关于如何将 EJS 与 Strapi 结合使用的指南
- 已安装 strapi-hook-ejs
- 将 .config/hook.json 更新为
...
{
"ejs": {
"enabled": true,
"layout": false,
"viewExt": "ejs",
"partial": true,
"cache": false,
"debug": true
}
}
...
- 将此添加到控制器,例如 ./api/api-name/controllers/api-name.js
module.exports = {
//GET /index
index: async (ctx) => {
ctx.render('home', {title: 'Hello world'});
}
};
- 在根文件夹中创建目录视图
- 在 ./views 中添加您的 ejs 模板
- 例子./views/home.ejs
<%= title %>
Side note: In the above example, I have used the "index" in the controller api-name.js file. Make sure your API ./api/api-name/config/routes.json point to it.
官方文档试过了,还是不行
https://github.com/strapi/strapi-docs/blob/master/files/views.md
这里是关于如何将 EJS 与 Strapi 结合使用的指南
- 已安装 strapi-hook-ejs
- 将 .config/hook.json 更新为
...
{
"ejs": {
"enabled": true,
"layout": false,
"viewExt": "ejs",
"partial": true,
"cache": false,
"debug": true
}
}
...
- 将此添加到控制器,例如 ./api/api-name/controllers/api-name.js
module.exports = {
//GET /index
index: async (ctx) => {
ctx.render('home', {title: 'Hello world'});
}
};
- 在根文件夹中创建目录视图
- 在 ./views 中添加您的 ejs 模板
- 例子./views/home.ejs
<%= title %>
Side note: In the above example, I have used the "index" in the controller api-name.js file. Make sure your API ./api/api-name/config/routes.json point to it.