javascript - Meteor.js: how to pass the data context of one helper to another helper? -
so if have template:
<template name="mytemplate"> {{foo}} </template>
and template helper:
template.mytemplate.foo = function() { blah = session.get('blah'); // code stuff blah return blah; };
and have template:
<template name="myothertemplate"> {{foo}} </template>
and want data context of template same previous template do?
it first occurred me using {{#with}} might right approach seems work if scope of second template inside first.
ultimately able use helpers defined 1 template within template , know how that.
seems asking 1 of 2 questions:
if using
myothertemplate
insidemytemplate
, context of other template same one, unless explicitly pass else second argument of partial.<template name="mytemplate"> {{> myothertemplate foo}} </template>
if want use helper across more 1 template, declare in global helper. make
{{foo}}
available in templates:handlebars.registerhelper("foo", function() { blah = session.get('blah'); // code stuff blah return blah; });
if want make own data context on fly (this rare), following:
<template name="mytemplate"> {{{customrender}}} </template> template.mytemplate.customrender = function() { return template.othertemplate({ foo: something, bar: somethingelse, foobar: template.mytemplate.foo // pass in helper different name }); };
this object iron-router pass template on render. note wiill need use triple handlebars
{{{ }}}
or usenew handlebars.safestring
tell not escape template.
Comments
Post a Comment