Подтвердить что ты не робот

Flatiron.js/пластины частичные шаблоны?

Итак, я только начал работать с flatironjs и plates". Я пытаюсь выяснить, как я могу иметь основной шаблон макета, а затем частичный шаблон, который загружает контент в шаблон основного макета, аналогичный тому, как это делает expressjs...

С expressjs есть layout.js и, возможно, index.js. index.js заполняет область содержимого layout.js. Похоже, это будет испечено. Я не вижу способа сделать это на основе документации.

4b9b3361

Ответ 1

Основной шаблон макета (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>