Meteor:如何从模板助手返回模板?

Par*_*rkL 3 coffeescript meteor

在这里.我正试图将一个任意模板"注入"另一个模板.但似乎我做错了:)

whatever.html:

<template name="parent">
    {{child}}
</template>

<template name="child1">
  I'm child 1
</template>

<template name="child2">
  I'm child 2
</template>
Run Code Online (Sandbox Code Playgroud)

whatever.coffee

x = "child1"
Template.parent.child = -> Template[x](@)
Run Code Online (Sandbox Code Playgroud)

这将创建"带注释的HTML"(http://docs.meteor.com/#template_call)作为结果,但{{child}}助手的输出是html编码的,因此不会被解释.

我知道我可以使用Template.myTemplate.rendered事件使用jQuery将模板直接添加到DOM.但这似乎是一个非常黑客的imho.如果可能的话,我宁愿帮助生成一个帮助器.

这样做的"正确"方法是什么?是否有可能在模板中取消结果?反应性会有效吗?

在此先感谢!! 1

问候

Pra*_*ant 17

A {{doubleBrace}}转义HTML {{{tripleBrace}}}而不转义HTML并按原样呈现它.

编辑:我提到了其他方式.

来自Handlebars文档 - "Handlebars HTML-escapes {{expression}}返回的值.如果您不希望Handlebars转义值,请使用'triple-stash'."

  • 谢谢!所以这在技术上是重复的;)http://stackoverflow.com/questions/7168469/handlebars-template-rendering-template-as-text (2认同)