makeBoundHelper alternative in Ember 2.0

后端 未结 1 1946
北荒
北荒 2021-01-19 01:25

I\'ve been injecting Google DFP ads in my blog-posts by using a bound helper so far. Since all Handlebars APIs have been removed in Ember 2.0 what can I use as of Em

相关标签:
1条回答
  • 2021-01-19 01:55

    You would use the Ember.Helper.helper syntax:

    import Ember from 'ember';
    
    const { Helper: { helper }, run: { schedule }, $ } = Ember;
    
    export function helperName(params, hash) {
      let parsedHtml = $('<div />').html(params[0])
    
        // Push the ads after the divs have been rendered
       schedule('afterRender', function() {
          googletag.cmd.push(function() { googletag.display('div-gpt-ad-111111111-0'); });
        }) 
      }
    
      return parsedHtml.html();
    }
    
    export default helper(helperName);
    

    Params is an array of all the values that you pass to the helper in your template such as {{my-helper val1 val2 val3}} params[0] is val1 and so on, the hash is an object containing all the properties you set on the helper {{my-helper val1 val2 property1=myPropValue}} and you would access it via hash.property1.

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