flatiron.js/plate部分模板?

xsp*_*ydr 11 node.js flatiron.js

所以,我刚开始使用flatironjs和" plate ".我试图找出如何拥有一个主布局模板,然后是一个部分模板,将内容加载到主布局模板中,类似于expressjs的做法...

使用expressjs有layout.js和index.js.index.js填充layout.js的内容区域.好像这会被烘焙我根本没有找到基于文档的方法.

Ben*_*uch 16

主布局模板(template.html):

<h1>This is the main template.</h1>
<div id="main"></div>
Run Code Online (Sandbox Code Playgroud)

部分(partial.html):

<p>This is the partial that should be rendered into the main template.</p>
Run Code Online (Sandbox Code Playgroud)

然后你可以这样做:

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});
Run Code Online (Sandbox Code Playgroud)

所以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>
Run Code Online (Sandbox Code Playgroud)