Is there a way to pass variables into templates in Meteor?

前端 未结 9 2114
深忆病人
深忆病人 2020-12-01 01:37

I\'ve been experimenting with Meteor and ran into something I couldn\'t figure out. For fun, I was trying to make a slot machine. I had the following HTML:

&         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 02:36

    Better Answer:

    The two solutions that are available to making a template context sensitive under the new Blaze layout are:

    1) Passing arguments to the template directly

    {{> contextSensitiveTemplate  context_1='x' context_2='y' }}
    

    2) Using a helper in the template that understands the context. Call the helper like this:

    {{ contextHelperName ../.. .. this }}
    

    And

    Template.contextSensitiveTemplate.contextHelperName = function(parent_template, current_template, current_value_inside_each_loop) {
      return context_dependent_value_or_html     
    }
    

提交回复
热议问题