获取模板和json文件并返回html

时间:2015-08-06 18:15:10

标签: html templates

我正在寻找一个模板引擎,它接受一个模板和一个json(或yaml,或类似的)并将其呈现为一个html文件。 喜欢这个

模板文件

{{pages}}
<div class="page">
<h1>{{title}}</h1>
<ul>
    {{instructions}}
        <li>{{instruction}}</li>
    {{/instructions}}
</div>
{{/pages}}

数据文件

pages:
  - title: My title
    instructions: 
      - Do this
      - Do that
  - title: Another title
    instructions:
      - Click here
      - Click there

呈现:

<div class="page">
  <h1>My title</h1>
  <ul>
    <li>Do this</li>
    <li>Do that</li>
</div>
<div class="page">
<h1>Another title</h1>
<ul>
    <li>Click here</li>
    <li>Click there</li>
</div>

有没有办法让渲染的html作为文件,以便我可以在像王子这样的其他工具中使用它?

1 个答案:

答案 0 :(得分:0)

有很多工具可以做这样的事情。没有特别的顺序,请尝试......

...或只是谷歌“模板引擎”。