templates - 如何在 Strapi 中使用 EJS
解决方案
这是有关如何将 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 %>
旁注:在上面的示例中,我在控制器 api-name.js 文件中使用了“索引”。确保您的 API ./api/api-name/config/routes.json指向它。
推荐阅读
- typescript - 如何修复打字稿查找类型中的错误?
- java - 如果 SQLite 中的列为空,则显示“No Title”
- python - 如何在 Tensorflow 2 中解码示例(从 1.12 移植)
- html - CSS Grid在换行后具有自动流可能的最小列数
- wcf - 从服务器收到的身份验证标头.. BASIC - WFC - NET CORE
- google-apps-script - getValue() 不从源文件中返回数据,Google App Script
- javascript - 用 Applescript 在线替换文本
- kubernetes - Kubernetes 网络插件
- php - php排序多嵌套数组
- codeigniter - codeigniter form_error() 在表单控件旁边没有显示错误