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:

  1. if using myothertemplate inside mytemplate, context of other template same one, unless explicitly pass else second argument of partial.

    <template name="mytemplate">   {{> myothertemplate foo}} </template> 
  2. 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; }); 
  3. 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 use new handlebars.safestring tell not escape template.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -