所以,我刚开始使用flatironjs并且“板“。我试图找出如何拥有一个主要的布局模板,然后是一个部分模板,将内容加载到主布局模板中,类似于expressjs的做法......
使用expressjs有layout.js和index.js。 index.js填充layout.js的内容区域。好像这会被烘焙我根本没有找到基于文档的方法。
所以,我刚开始使用flatironjs并且“板“。我试图找出如何拥有一个主要的布局模板,然后是一个部分模板,将内容加载到主布局模板中,类似于expressjs的做法......
使用expressjs有layout.js和index.js。 index.js填充layout.js的内容区域。好像这会被烘焙我根本没有找到基于文档的方法。
主布局模板(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>
主布局模板(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>