首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flatiron.js/plate部分模板?

Flatiron.js/plate部分模板?
EN

Stack Overflow用户
提问于 2012-03-27 23:19:37
回答 1查看 1.2K关注 0票数 11

所以,我刚开始使用flatironjs和"plates“。我正在尝试弄清楚如何才能有一个主布局模板,然后再有一个分部模板,将内容加载到主布局模板中,类似于expressjs是如何做到的……

有了expressjs,就有了layout.js,也许还有index.js。index.js填充layout.js的内容区域。这看起来像是烘焙的,我看不到基于文档的方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-10 00:49:12

主布局模板(template.html):

代码语言:javascript
复制
<h1>This is the main template.</h1>
<div id="main"></div>

部分(partial.html):

代码语言:javascript
复制
<p>This is the partial that should be rendered into the main template.</p>

然后你可以这样做:

代码语言:javascript
复制
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)应该会给你:

代码语言:javascript
复制
<h1>This is the main template.</h1>
<div id="main">
  <p>This is the partial that should be rendered into the main template.
</p>

票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9892496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档