think-view-eta
v1.0.0
Published
think-view-eta for ThinkJS
Readme
think-view-eta
Use eta template engine to render view files for ThinkJS 3.x.
Install
npm install think-view-etaHow to Use
Edit the config file src/config/adapter.js and add the following options:
const eta = require('think-view-eta');
exports.view = {
type: 'eta',
common: {
viewPath: path.join(think.ROOT_PATH, 'view'),
extname: '.eta',
sep: '_' // separator between controller and action
},
eta: {
handle: eta
}
}Default Options
const defaultOptions = {
cache: false,
autoEscape: true
};Custom Options
All available options can be found at https://eta.js.org/docs/learn/configuration
exports.view = {
type: 'eta',
eta: {
handle: eta,
options: {
tags: ['{{', '}}'],
varName: 'data'
}
}
}beforeRender
You can use the beforeRender callback to configure the eta instance before rendering:
exports.view = {
type: 'eta',
eta: {
handle: eta,
beforeRender: (etaInstance, EtaClass, options) => {
etaInstance.configure({ cache: true });
}
}
}Template Syntax
Eta uses <%= it.varName %> for HTML-escaped interpolation and <%~ it.varName %> for raw/unescaped output.
<h1><%= it.title %></h1>
<p><%~ it.rawHtml %></p>
<% if (it.show) { %>
<span>visible</span>
<% } %>For more details, visit https://eta.js.org.
