Question

There is something I do not get with Meteor's template engine, being used with Mustache I can change the scope of the json data souce simply by enclosing the code with a {{#newscope}}{{/newscope}. In practice this does not seems to work the same way with the handlebars

Here is my template data source

   Template.aName.data = function()
     {
         return {"foo":"bar"};
     };

Then here is my html template (partial)

<template name="aName">
    {{data.foo}} // This prints "bar"

    {{#data}}
    {{foo}} // This does not prints anything but [object Object] (I expected "bar")
    {{/data}}

    {{#data.foo}}
    {{.}} // This prints "bar" but oh so ugly…
    {{/data.foo}}
</template>

What's the point ?

Was it helpful?

Solution

Use the with keyword to change the scope

<template name="aName">
    {{#with data}}
    {{foo}} // prints "bar" as expected
    {{/with}}
</template>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top