Search code examples
javascriptmeteorspacebarsmeteor-helper

How can I pass parameters to an helper?


I want to pass some parameters from my HTML to my meteor helper.

Can I do something like this? ->

{{myHelper "customText"}}

or

{{myHelper context="customText"}}

If so, how do I get back the string "customText"? Is it something like this? ->

"myHelper": function(context){
    return this.dataset[context]?"success":"danger"
},

thanks!


Solution

  • Pass parameters to a help like this:

    <template name="myTemplate">
    ...
    {{myHelper param}}
    ...
    </template>
    

    Then access it in your .js file:

    Template.myTemplate.helpers({
       myHelper: function(param) {
          // do anything with param
       }
    });