Passing data to a dynamic template

With meteor updates to 0.8, my old code stops working.

Handlebars.registerHelper('getTemplate', function(id, context) {
    return Template[id](context);
}); 

<template name="main">
    ....
    {{{getTemplate templateName context}}}
    ....
</template>

//somewhere in other template 
Template.main.context = {name:value};

Thus, I was able to display my own template with user data. Now I can’t find a way to pass contextto the dynamic template. With both flame templateNameand contextundefined. Any advice?

+4
source share
2 answers

Meteor> = 0.8.2

You can use the helper to UI.dynamicrender the template with context, which are both specified dynamically. See this issue for more information .

Meteor <0.8.2

-.

  • Handlebars.registerHelper UI.registerHelper, .

  • .


, , . , . - :

<body>
  {{> main}}
</body>

<template name="main">
  {{> getTemplate context}}
</template>

<template name="dogs">
  <p>There are {{animals}} dogs!</p>
</template>

<template name="cats">
  <p>There are {{animals}} cats!</p>
</template>
Session.setDefault('templateName', 'dogs');
Session.setDefault('templateContext', {animals: 10});

Template.main.getTemplate = function() {
  return Template[Session.get('templateName')];
};

Template.main.context = function() {
  return Session.get('templateContext');
};
+2

@dgreensp, MDG, Blaze, Ticket # 2007 - HTML , , , 0.8.0.

:

var toHTMLWithData = function (kind, data) {
  return UI.toHTML(kind.extend({data: function () { return data; }}));
};

github , .

+1

Source: https://habr.com/ru/post/1535473/


All Articles