Variables and Functions In Templates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blueprint
    Active Community Member
    • Jan 2019
    • 223

    Variables and Functions In Templates

    Is there any way of declaring a variable inside a Template?

    For example, if I wanted to increment a running counter for records, it would be quite nice if I could do something like:

    {{#var counter}}
    ...
    {{counter++}}

    Likewise, if I wanted to sum up a number of fields (i.e. a weight field) and then display the total in the Template footer.

    Can this be done in the Template (rather than in the Entity as a formula)?
  • yuri
    Member
    • Mar 2014
    • 8624

    #2
    No. Templates very restricted in abilities. The lib we use doesn't give any room for enhancing.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • blueprint
      Active Community Member
      • Jan 2019
      • 223

      #3
      yuri Ok, no problemo.

      Comment

      • Andorxor
        Member
        • May 2019
        • 65

        #4
        I think that should work,but if you already have a customview you could just sum up the weights before giving the conext to the template.
        PHP Code:
         HandleBars.registerHelper("counter",function(root){root.weightSum += this.weight}); 
        
        HTML Code:
        <table>
        {{#each heavyThings}}
        {{counter @root}}
        <tr><td>{{name}}</td><td>{{weight}}</td><(tr>
        {{/each}}
        </table>
        <footer>
        {{weightSum}}
        </footer>
        Last edited by Andorxor; 09-26-2019, 11:52 AM.

        Comment

        Working...