flatiron.js/plates partial templates?

后端 未结 1 1487
迷失自我
迷失自我 2021-02-14 05:56

So, I just started working with flatironjs and \"plates\". I\'m trying to figure out how I can have a main layout template and then a partial template that loads content into th

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-14 06:35

    Main layout template (template.html):

    This is the main template.

    Partial (partial.html):

    This is the partial that should be rendered into the main template.

    Then you can do this:

    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});
    

    So console.log(rendered)should give you:

    This is the main template.

    This is the partial that should be rendered into the main template.

    0 讨论(0)
提交回复
热议问题