Templates 如何在Strapi中使用EJS

Templates 如何在Strapi中使用EJS,templates,ejs,strapi,Templates,Ejs,Strapi,我尝试了官方文档,但这不起作用 以下是如何将EJS与Strapi一起使用的指南 已安装的strapi吊钩ejs 使用更新.config/hook.json 将其添加到控制器,例如./api/api name/controllers/api-name.js 在根文件夹中创建目录视图 在./views中添加您的ejs模板 示例./views/home.ejs 旁注:在上面的示例中,我使用了controllerapi-name.js文件中的“index”。确保您的API./API/API

我尝试了官方文档,但这不起作用


以下是如何将EJS与Strapi一起使用的指南

  • 已安装的strapi吊钩ejs
  • 使用更新.config/hook.json
  • 将其添加到控制器,例如./api/api name/controllers/api-name.js
  • 在根文件夹中创建目录视图
  • 在./views中添加您的ejs模板
  • 示例./views/home.ejs

旁注:在上面的示例中,我使用了controllerapi-name.js文件中的“index”。确保您的API./API/API name/config/routes.json指向它

...
{
  "ejs": {
    "enabled": true,
    "layout": false,
    "viewExt": "ejs",
    "partial": true,
    "cache": false,
    "debug": true
  }
}
...
module.exports = {
  //GET /index
  index: async (ctx) => {
    ctx.render('home', {title: 'Hello world'});
  }
};