前端模板Nunjucks简介
生活随笔
收集整理的這篇文章主要介紹了
前端模板Nunjucks简介
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
參考資料:?https://mozilla.github.io/nunjucks/
https://mozilla.github.io/nunjucks/templating.html
https://mozilla.github.io/nunjucks/api.html
?
常用API
render
nunjucks.render(name, [context], [callback])
var res = nunjucks.render('foo.html'); var res = nunjucks.render('foo.html', { username: 'James' }); nunjucks.render('async.html', function(err, res) { });?
renderString
nunjucks.renderString(str, context, [callback]) 返回渲染后的原始字符串。
var res = nunjucks.renderString('Hello {{ username }}', { username: 'James' }); //輸出 Hello James?
configure
nunjucks.configure([path], [opts]); path 默認當前路徑,模板文件所在的路徑。
nunjucks.configure('views', { //views為模板文件所在的目錄autoescape: true,express: app,watch: true });?
getTemplate
env.getTemplate(name, [eagerCompile], [callback]) Retrieve the template named name
var tmpl = env.getTemplate('page.html', true); //返回模板文件 page.html 的內(nèi)容?
express
env.express(app) 用做服務(wù)端渲染
var app = express(); env.express(app);app.get('/', function(req, res) {res.render('index.html'); });?
constructor
new Template(src, [env], [path], [eagerCompile])
var tmpl = new nunjucks.Template('Hello {{ username }}'); tmpl.render({ username: "James" }); // -> "Hello James"?
轉(zhuǎn)載于:https://www.cnblogs.com/zourong/p/6648364.html
總結(jié)
以上是生活随笔為你收集整理的前端模板Nunjucks简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jsp内置对象+Servlet
- 下一篇: 清除webkit浏览器css设置滚动条