3

n00b here. I'm trying to "inject" an arbitrary template into another. But it seems like I'm doing it wrong :)

whatever.html:

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

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

<template name="child2">
  I'm child 2
</template>

whatever.coffee

x = "child1"
Template.parent.child = -> Template[x](@)

This will create "annotated HTML" (http://docs.meteor.com/#template_call) as the result, but the output of the {{child}} helper is html-encoded and thus is not interpreted.

I'm aware that I could use the Template.myTemplate.rendered event to add the template directly to the DOM using jQuery. But that seems like quite a hack imho. I'd rather have a helper generate that if possible.

What is the "right" way to do this? Is it possible to unescape the result in the template? Will reactivity work?

Thanks in advance!!1

Regards

ParkL
  • 45
  • 1
  • 4

1 Answers1

17

A {{doubleBrace}} escapes HTML while a {{{tripleBrace}}} does not escape HTML and renders it as is.

EDIT: I mentioned it other way around.

From Handlebars docs - "Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the 'triple-stash'."

Prashant
  • 1,825
  • 1
  • 15
  • 18
  • 2
    Thanks! So this is technically a duplicate ;) http://stackoverflow.com/questions/7168469/handlebars-template-rendering-template-as-text – ParkL Mar 04 '13 at 16:53
  • Yes. It will be merged or closed later by moderators. – Prashant Mar 04 '13 at 16:56