简体   繁体   English

流星:如何在车把内使用车把

[英]Meteor: How to use handlebars within handlebars

I would like to use to refer to another template within an {{#each}} loop 我想用来引用{{#each}}循环中的另一个模板

html: 的HTML:

{{#each listOfItems}}
 {{>{{variableOne}}}}
{{/each}}

which should render 应该渲染

<Template name="one">
 One
</Template>

or 要么

<Template name="two">
 Two
</Template>

depending on the js 取决于js

other tried syntax include 其他尝试的语法包括

{{>'{{variableOne}}'}}

or 要么

{{>Template.dynamic template={{variableOne}}}}

Any help or workaround greatly appreciated! 任何帮助或解决方法,不胜感激!

Not sure what are you trying to accomplish. 不确定您要完成什么。 I'm assuming you are using Blaze rendering engine. 我假设您正在使用Blaze渲染引擎。 If you want to pass parameters try this: 如果要传递参数,请尝试以下操作:

{{#each}}
  {{> TemplateName variable=variable}}
{{/each}}

Or if you want to show certain template depending on variable value try this (watch out - eq is meant as global helper for comparing values): 或者,如果您想根据变量值显示某些模板,请尝试以下操作(注意-eq是用于比较值的全局帮助器):

{{#each}}
  {{#if variable eq 1}}
    {{> TemplateOne}}
  {{else}}
    {{> TemplateTwo}}
  {{/if}} 
{{/each}}

Assuming that the list you iterate over contains the template names, this will get you what you want: 假设您要遍历的列表包含模板名称,这将为您提供所需的信息:

html: 的HTML:

<template name="hello">
  {{#each template in myTemplates}}
    {{> Template.dynamic template=template }}
  {{/each}}
</template>

<template name='foo'>foo-template</template>
<template name='bar'>bar-template</template>

js: js:

Template.hello.helpers({
  myTemplates() {
    return ['foo', 'bar'];
  },
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM