本文介绍了如何包含在YMF中定义的部分(Assemble.io / Handlebars.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我使用assemble.io为简单的网页生成一些静态文件。 现在我想定义YAML Front Matter中的部分列表,该列表应包含在生成的页面中。 我想要这个 < div class =slides > {{> slide-intro}} {{> slide-welcome}} {{> slide-goodbye}} < / div> 被这样的东西取代: --- 幻灯片: - 幻灯片介绍 - 幻灯片欢迎 - 幻灯片再见 - - < div class =slides> {{#each slides}} {{> this}} {{/ each}} < / div> 所以,我想使用存储在这个(例如 slide-welcome )作为要包含的部分的名称。 我发现使用 {{> this}} 不起作用,但我不知道该在哪里寻找解决方案。 任何人都可以帮我解决问题吗? 解决方案 Handlebars 3介绍 Dynamic Partials ,您可以像这样使用它们: --- 幻灯片: - 幻灯片介绍 - 幻灯片欢迎 - slide-goodbye --- < div class =slides> {{#each slides}} {{> (lookup ../slides @index)}} {{/ each}} < / div> 但是,汇编0.4.x使用的是Handlebars 1,所以切换到 grunt-assemble ,它使用Handlebars 3. grunt-assemble是基于相同的代码,它只是被移动以反映它是一个咕噜声插件。 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? 解决方案 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. 这篇关于如何包含在YMF中定义的部分(Assemble.io / Handlebars.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 00:24