jsrender / components : passing extra attributes



  • Hello,
    How do you pass extra attributes to components using jsrender ?
    I have tried this but I get "Unmatched or missing {{/prepareData}}, in template:"

    {{:~prepareData(@root.name)}}
      {{:~component("./compo")}}
    {{/prepareData}}
    

    My prepareData function is declared like this:

    function prepareData(someAttribute, options) {   
        return options.fn({
            ...this,
            someAttribute
        })
    }
    

    Thanks !



  • https://playground.jsreport.net/w/anon/ogCgSXL9

    {{prepareData "hello"}}
       {{:~component("./c1")}}
    {{/prepareData}}
    
    function prepareData(v) {
        return this.tagCtx.render({
            propA: v
        })
    }
    


  • However, I recommend using mainly handlebars. Some new recipes support just that.



  • Thanks for the quick answer. I will consider going back to Handlebars but the fact that you have to write a function for every single test is really annoying (rather than directly doing something like {{if field>=2}}...{{/if}}). I will create a new thread on the question.



  • This post is deleted!

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.