Is it possible to define helper that is shared across multiple templates?



  • I have many small helpers like:

    function toJSON(data) {
      return JSON.stringify(data);
    }
    

    that is used in the template like so: var projectsDataJson = {{:~toJSON(projectsData)}}
    and would like to reuse those helpers across multiple templates. Is there a way to do so?


  • administrators

    yes, you can add those shared helpers as an asset, see here for the docs and see this post to find some explanations and a screenshot. just note that when you mark an asset as a global helper it will be shared to all templates, if you just want to share the helpers to just some of them, then you can put the helpers in an asset (but don't mark it as global helper) and then import the asset in each template helpers section, if you will do that then make sure to import the asset with the right encoding, in this case string encoding



  • Thank you!


Log in to reply
 

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