怎么在node环境中使用parse Smarty模板
作者
这期内容当中小编将会给大家带来有关怎么在node环境中使用parse Smarty模板,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
//index.js: constexpress=require('express'); constsmarty4Js=require('smarty4Js'); constpath=require('path'); constapp=express(); constsmartyHelper=newsmarty4Js(); constbasePath=path.resolve('./'); smartyHelper.setBasedir(basePath); constcompiler=smartyHelper.compile('./index.tpl'); consthtml=compiler.render({ title:'node-parse-smarty', body:'Smarty' }); console.log(html); app.get('/',(req,res)=>{ res.header('text/html'); res.end(html); }); app.listen(3000,()=>{ console.log('appisrunat3000port'); });
//index.tpl:{%$title%} {%$body%}