1

Im trying to pass a parameter from one template to other in meteor.js i want to do this for DRY sake The first template looks like this

template(name="myPage") 
   h3.uppercase.amarillo-hogar 
      +editaMl(data=this collection="categorias" field="titulo")

template(name="editaMl")
        if i18n_isCurrentLanguage 'es'
            | {{collection}} {{field}}
            +editableText(context=data collection=collection field=field userCanEdit=userCanEdit acceptEmpty=true substitute='<i class="fa fa-pencil"></i>')
        else 
            +editableText(collection=collection field=field userCanEdit=userCanEdit acceptEmpty=true substitute='<i class="fa fa-pencil"></i>')

this is so i can stop repeating myself with every translation field but cant work around passing a parameter value to another template parameter value

i use jade, now in html for those who do not like jade

<template name="myPage">
    <h3 class="uppercase amarillo-hogar>{{> editaMl collection="categorias" field="titulo"}}</h3>
</template

<template name="editaMl">
    {{#if i18n_isCurrentLanguage 'es'}}
        {{> editableText collection=collection field=field }}
    {{/if}}
    {{#else}}
        {{> editableText collection=collection field=field }}
    {{/else}}
</template>

just if you want to know, im using babraham editable text package and tap_i18n with tap_i18n ui for translating

Cant find the reason my helper returns an object when used like this in the content {{collection}} but when used as parameter in the child template does nothing

Code updated and SOLVED

  • `collection=collection field=field` should work shouldn't it? But `en.field` won't, you'll need to pass in the English field name from the parent. – Michel Floyd Oct 21 '15 at 02:38
  • I tought the same, actually is written like that and is not working im passing the spacebars in the template just to see the info parsed, and it does parse it, but doesnt work when i try to reuse the parameters in the second parameters – Israel Ortiz Cortés Oct 21 '15 at 02:46
  • Possibly try `this.collection` and `this.field` – Michel Floyd Oct 21 '15 at 03:31
  • I DID IT first i set the data context in the parent template template(name="myPag") +editaMl(data=this field="titulo") template(name="editaMl") +editableText(context=data collection="categorias" field=field userCanEdit=userCanEdit acceptEmpty=true substitute='') – Israel Ortiz Cortés Oct 21 '15 at 04:15
  • This answer solved my question and problem http://stackoverflow.com/questions/29916651/passing-multiple-parameters-between-templates-in-meteor – Israel Ortiz Cortés Oct 21 '15 at 04:22

1 Answers1

0

You can use:

Template.registerHelper('yourHelperName', function() {
   // your helper
});

It creates a helper available in all templates.

KG32
  • 150
  • 10