Reputation: 805
I've seen the various discussions on using a dynamically selected template in Meteor (ex. here, here, and here).
But what if I want to pass a parameter into the dynamic template, that is:
{{> UI.dynamic template=templateName data=dataObj param1=17}}
Is there any way to do this? Essentially, I have three templates, which all take the same parameter. I want to create a generic template that can dynamically call one of those three, passing along the parameter.
It feels like there should be a way to do it with a helper, but I can't quite figure it out.
-Dov
Upvotes: 1
Views: 1816
Reputation: 805
Thanks to the comment from David Weldon, I managed to overcome my writer's block.
Here's the answer for others who manage to end up on this page.
HTML:
<head>
<title>dynamic test</title>
</head>
<body>
{{> generic detailsTemplate="y"}}
</body>
<template name="generic">
{{> Template.dynamic template=detailsTemplate data=updatedata}}
</template>
<template name="x">
Here
edit={{edit}} - this shows nothing if the data context isn't modified
</template>
Javascript:
Template.generic.helpers({
updatedata: function () {
this.edit = true;
return this;
}
});
Upvotes: 2