How to include Partials defined in YMF (Assemble.io / Handlebars.js)

柔情痞子 提交于 2019-12-11 12:58:09

问题


I use assemble.io to generate some static files for a simple webpage.

Now i would like to define a list of partials in YAML Front Matter that should be included in the generated page.

I want this

<div class="slides">
  {{>slide-intro}}
  {{>slide-welcome}}
  {{>slide-goodbye}}
</div>

to be replaced by something like this:

---
slides:
  - slide-intro
  - slide-welcome
  - slide-goodbye
---
<div class="slides">
  {{#each slides}}
    {{>this}}
  {{/each}}
</div>

So, I want to use the variable content stored in this(e.g. slide-welcome) to be used as the name of a partial to be included.

I see that using {{>this}} is not working, but i have no clue where to look for the solution.

Can anybody help me out?


回答1:


Handlebars 3 introduced Dynamic Partials and you would use them like this:

---
slides:
  - slide-intro
  - slide-welcome
  - slide-goodbye
---
<div class="slides">
  {{#each slides}}
    {{> (lookup ../slides @index) }}
  {{/each}}
</div>

However, assemble 0.4.x is using Handlebars 1, so switch to grunt-assemble, which uses Handlebars 3. grunt-assemble is the same code based, it's just been moved to reflect that it's a grunt plugin.



来源:https://stackoverflow.com/questions/30708243/how-to-include-partials-defined-in-ymf-assemble-io-handlebars-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!