Announcement

Collapse
No announcement yet.

Display array field as a list using a template

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display array field as a list using a template

    I have noticed that when a field type array is set as "displayAsList" it displays fine in detail view but if I add the same field to a template and print to PDF the field shows as a joined string and not as a list.

    Same case for a field type Checklist.

    Is there a way to actually display an array or checklist field as a list using a template ?

    Thanks in advance to anybody who can help.
    Last edited by telecastg; 01-10-2020, 06:15 PM.

  • #2
    Hello telecastg,
    maybe in espoCRM 5.8... we can define custom helper template .. then return a array and make in template a : {{#each ...}}

    else i have another (certainly bad) solution who work :

    custom service :
    PHP Code:
    public function loadAdditionalFields(Entity $entity)
            foreach (
    $row as $i => $v) {            
                
    $activityDataList[$i] = (object) $v;
            }

    and
    public function 
    loadAdditionalFieldsForPdf(Entity $entity
    and in pdf template use {{#each ...}}

    i think the goal is return a array of objet of the field

    it's just my skill

    Regards
    Last edited by item; 01-11-2020, 12:41 AM.

    Comment


    • #3
      Thanks item, I appreciate your response and will give it a try !

      By the way I don't believe that there are bad solutions ;-) at least you provided one !

      Thanks again

      Last edited by telecastg; 01-11-2020, 04:05 AM.

      Comment


      • #4
        Hi item thanks for pointing me out to the solution, it turned out to be a lot simpler than I thought.

        You were right, all I needed to do is to use the {{#each}} loop and render the array field as a list instead of trying to use a simple placeholder as I was doing, although thankfully it wasn't necessary to do any coding.

        Here's the template snippet for an array field called materialsPurchased

        Code:
        <ul class="list-group">
          {{#each materialsPurchased}}
            <li class="list-group-item list-row">{{this}}</li>
          {{/each}}
        </ul>
        I found this out by searching for help with Handlebars which is something on which I am still not proficient at all !

        Note: If printing to PDF the list with the code above will be rendered as an un-styled list because of the TCPDF engine limitations.

        Alternative styling to display array field making it more compatible with TCPDF
        Code:
        {{#each materialsPurchased}}
        <table><tbody><tr><td>{{this}}</td></tr></tbody></table>         
        {{/each}}
        Regards
        Last edited by telecastg; 01-11-2020, 09:25 PM.

        Comment

        Working...
        X