custom Handlebars helper - parameter is not resolved

后端 未结 1 1499
无人及你
无人及你 2020-12-19 16:18
# here is CreditCards controller context
{{#with controllers.currentCardCategory}}
  {{#each property in cardProperties}}
    {{#is property.symbol \'your_savings\'}         


        
相关标签:
1条回答
  • 2020-12-19 16:50

    I am not certain about the context of your code, but it seems like you are looking for registerBoundHelper with a block helper. This isn't supported. You will run into this warning,

    Assertion failed: registerBoundHelper-generated helpers do not support use with Handlebars blocks.

    An alternative way to do what you are doing is to use a view helper instead. A view helper is like a helper but can render with a custom template.

    For instance a CardItemView would be,

    App.CardItemView = Em.View.extend({
      templateName: 'cardItemTemplate'
    });
    
    Em.Handlebars.registerHelper('cardItem', App.CardItemView);
    

    Where the cardItemTemplate is,

    <script type='text/x-handlebars' data-template-name='cardItemTemplate'>
      {{#if view.property.symbol}}
        <td class="td">{{yourSavings}}</td>
      {{else}}
        <td class="td">{{cardProperty view.property.symbol}}</td>
      {{/if}}
    </script>
    

    And you could use the helper like so,

    {{#with controllers.currentCardCategory}}
      {{#each property in cardProperties}}
        {{cardItem property=property etc}}
      {{/each}}
    {{/with}}
    

    You can pass in any number of properties as attributes. These will be bound to the CardItemView. And since it's a view anything a view does, like custom computed properties, can be done in CardItemView.

    0 讨论(0)
提交回复
热议问题