所以,我刚开始使用flatironjs和"plates“。我正在尝试弄清楚如何才能有一个主布局模板,然后再有一个分部模板,将内容加载到主布局模板中,类似于expressjs是如何做到的……
有了expressjs,就有了layout.js,也许还有index.js。index.js填充layout.js的内容区域。这看起来像是烘焙的,我看不到基于文档的方法。
发布于 2012-04-10 00:49:12
主布局模板(template.html):
<h1>This is the main template.</h1>
<div id="main"></div>部分(partial.html):
<p>This is the partial that should be rendered into the main template.</p>然后你可以这样做:
var fs = require("fs"),
Plates = require("plates");
// Read the two files from disk
var template = fs.readFileSync("template.html", "utf-8");
var partial = fs.readFileSync("partial.html", "utf-8");
// Render the partial into main.
// The data-key in the second param is matched to the id in the template.
// Plates renders the corresponding value - in this case the contents of
// partial.html - between the start and end tags with this id.
var rendered = Plates.bind(template, {main: partial});所以console.log(rendered)应该会给你:
<h1>This is the main template.</h1>
<div id="main">
<p>This is the partial that should be rendered into the main template.
</p>
https://stackoverflow.com/questions/9892496
复制相似问题