flatiron.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>