https://github.com/eggjs/egg-view-swig
egg view plugin for swig
https://github.com/eggjs/egg-view-swig
egg egg-plugin egg-view swig
Last synced: 5 months ago
JSON representation
egg view plugin for swig
- Host: GitHub
- URL: https://github.com/eggjs/egg-view-swig
- Owner: eggjs
- License: mit
- Created: 2017-04-10T11:39:19.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-10-24T04:03:57.000Z (over 6 years ago)
- Last Synced: 2025-10-07T18:43:54.855Z (8 months ago)
- Topics: egg, egg-plugin, egg-view, swig
- Language: JavaScript
- Size: 21.5 KB
- Stars: 2
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-view-swig
Use [swig](https://github.com/paularmstrong/swig) Template Engine.
**NOTE: swig is NOT MAINTAINED.**
Docs: http://node-swig.github.io/swig-templates
## Install
```bash
$ npm i egg-view-swig --save
```
## Usage
```js
// {app_root}/config/plugin.js
exports.swig = {
enable: true,
package: 'egg-view-swig',
};
```
Set mapping in config
```js
// {app_root}/config/config.default.js
exports.view = {
defaultViewEngine: 'swig',
mapping: {
'.tpl': 'swig',
},
};
// {app_root}/config/config.default.js
exports.swig = {
cache: true,
};
```
Set filter
```javascript
// {app_root}/app/extend/filter.js
exports.hello = name => `hi, ${name}.`;
// {app_root}/app/controller/{your_controller}.js
exports.home = function* (ctx) {
yield ctx.render('home.tpl', { name: 'egg' });
};
// home.tpl
{{ name | hello }}
```
Render in controller
```js
// {app_root}/app/controller/test.js
exports.home = function* (ctx) {
yield ctx.render('home.tpl', { name: 'swig view' });
};
```
## Configuration
see [config/config.default.js](config/config.default.js) for more detail.
## Questions & Suggestions
Please open an issue [here](https://github.com/eggjs/egg/issues).
## License
[MIT](LICENSE)