ruoyi-eggjs-handlebars
v1.1.5
Published
Egg plugin for handlebars
Downloads
25
Maintainers
Readme
ruoyi-eggjs-handlebars
Egg plugin for handlebars
安装
$ npm i ruoyi-eggjs-handlebars --save支持的 egg 版本
| egg 3.x | egg 2.x | egg 1.x | | ------- | ------- | ------- | | 😁 | 😁 | ❌ |
开启插件
// {app_root}/config/plugin.js
exports.handlebars = {
enable: true,
package: "ruoyi-eggjs-handlebars",
};配置
// {app_root}/config/config.default.js
config.handlebars = {
options: {
data: true,
compat: true,
knownHelpers: true,
knownHelpersOnly: false,
noEscape: false,
strict: false,
assumeObjects: false,
preventIndent: true,
ignoreStandalone: true,
explicitPartialContext: true
},
runtimeOptions: {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true
},
partialsPath: null, // 默认在 view.root 对应的 partials 目录下
ts: true, // CSS、JavaScript 外部资源引用是否添加时间戳
};更多配置说明请参考 Handlebars 官方文档
示例
基本使用
// controller
async index() {
const { ctx } = this;
await ctx.render('index.html', {
title: 'Hello Handlebars',
name: 'World'
});
}模板文件
<!-- app/view/index.html -->
<!DOCTYPE html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<h1>Hello {{name}}!</h1>
</body>
</html>内置 Helper
xif - 条件判断
{{#xif "age > 18"}}
<p>成年人</p>
{{else}}
<p>未成年</p>
{{/xif}}math - 数学运算
{{math value "+" 10}}
{{math value "-" 5}}
{{math value "*" 2}}
{{math value "/" 2}}
{{math value "%" 3}}link - 引入 CSS
{{link "/static/css/style.css"}}
<!-- 输出: <link rel="stylesheet" href="/static/css/style.css"> -->script - 引入 JS
{{script "/static/js/app.js"}}
<!-- 输出: <script src="/static/js/app.js"></script> -->Partials (代码片段)
在 app/view/partials/ 目录下创建代码片段:
<!-- app/view/partials/header.html -->
<header>
<h1>{{title}}</h1>
</header>在模板中使用:
{{> header}}关于 ruoyi-eggjs 项目
本插件是 ruoyi-eggjs 项目的核心组件之一。
ruoyi-eggjs 是一个基于 Egg.js 的企业级后台管理系统,参照若依(RuoYi)架构设计,提供完善的权限管理、用户管理、系统监控等功能,是快速开发企业级应用的最佳选择。
主要特性
- 🎯 完整的权限系统:基于 RBAC 的权限控制,支持细粒度权限管理
- 🚀 开箱即用:集成常用功能模块,快速启动项目开发
- 🔧 MyBatis 风格:采用 XML 风格的 SQL 编写,熟悉的开发体验
- 📦 模块化设计:松耦合的插件体系,按需使用
- 🛡️ 企业级安全:XSS 防护、SQL 注入防护、访问控制等
- 📊 系统监控:在线用户、登录日志、操作日志、定时任务等
项目地址
相关插件
- ruoyi-eggjs-cache - 缓存插件
- ruoyi-eggjs-mybatis - MyBatis 集成
- ruoyi-eggjs-mysql - MySQL 连接
- ruoyi-eggjs-ratelimiter - 限流插件
- ruoyi-eggjs-sqlite - SQLite 支持
- ruoyi-eggjs-handlebars - Handlebars 模板
联系方式
- 📮 Issues: 提交问题或建议
- 🌐 官网: https://www.undsky.com
- 💬 讨论: GitHub Discussions
贡献指南
欢迎提交 Issue 和 Pull Request!
如果这个项目对你有帮助,请给我们一个 ⭐️ Star 支持一下!
