Problem with broken loop {{#each}} while saving PDF template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arturkulik
    Junior Member
    • Apr 2025
    • 25

    #1

    Problem with broken loop {{#each}} while saving PDF template

    What can be wrong if i create templete ( via code view) with



    <table class="bordered" style="width: 100%; border-collapse: collapse;"><tbody>

    <tr style="background:#eee;border-bottom:1px solid #eee;">
    headers
    </tr>

    {{#each............ }}
    <tr>
    DATA
    </tr>
    {{/each}}

    </table>



    after saving and editing again i got {{#each}} jumps before whole table:

    Click image for larger version  Name:	 Views:	0 Size:	8.0 KB ID:	117624
    Last edited by arturkulik; Yesterday, 11:12 AM.
  • yuri
    Member
    • Mar 2014
    • 8942

    #2
    It was covered many many times on the forum.

    The recommended way is the 'iterate' attribute. https://docs.espocrm.com/user-guide/...#each-iterator
    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

    • victor
      Active Community Member
      • Aug 2022
      • 904

      #3
      Hi arturkulik,

      From EspoCRM documantation:
      Using <tr> and <td> tags along with {{#each}} helper is not recommended as it breaks markup of a contenteditable element.
      A practically identical topic using iterate instead of {{#each}} has already been discussed on the forum: https://forum.espocrm.com/forum/deve...email-template with specific examples.

      Comment

      • arturkulik
        Junior Member
        • Apr 2025
        • 25

        #4
        after changing to iterate - i lost coding ( font still this same) and data, it sees records but not content. probably it should be addressed other way

        Comment

        • yuri
          Member
          • Mar 2014
          • 8942

          #5
          What EspoCRM version? There was a bug a couple versions back that has been already fixed.
          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


          • yuri
            yuri commented
            Editing a comment
            That bug was fixed in 9.0.3.
        • arturkulik
          Junior Member
          • Apr 2025
          • 25

          #6
          ok
          curr 8.4.2 we are upgrading to 9.1.1 in 30minutes,

          Thank You,

          If i need to start @index incrementing will it work to?

          Comment

          • yuri
            Member
            • Mar 2014
            • 8942

            #7
            Index does not work. If you need it, you can still use the each helper but wrapping it in HTML comments to prevent the markup from getting broken.
            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


            • yuri
              yuri commented
              Editing a comment
              Though it may still work with the attribute. I'm not sure.
          • arturkulik
            Junior Member
            • Apr 2025
            • 25

            #8
            I guess i found a bug
            (espo 9.1.1 AdvPack 3.9.0)

            when all previous problems fixed with 9.1.1 i got:

            I wanto to disable whole row when one of arguments match pattern, i can not do it before iterate, because loop will not catch it, co i want to replace empty columns with one merged with some info

            <tr iterate ={{}}>
            <td> col1</td>
            <td> col2</td>
            {{#if conditions_to_merge_columns}}
            <td colspan="3">empty cumulated row </td>

            {{else}}
            <td>col3</td><td>col4</td> <td>col5</td>

            {{/if}}
            </tr>

            after saving it works, after editting
            {{#if conditions_to_merge_columns}}
            {{else}}
            {{/if}}

            is thrown before table


            Comment

            • victor
              Active Community Member
              • Aug 2022
              • 904

              #9
              In HTML tables, you need to use x-if="{{...}} instead of the usual {{#if}}...{{/if}}: https://docs.espocrm.com/user-guide/...attribute-x-if.

              Currently, there is only one Conditional rendering attribute: x-if="{{...}} (does not yet exist, for example, x-else="{{...}} or x-unless="{{...}}). And that is why for each unique condition you need to use a unique separate element with a unique x-if="{{...}}.

              Again, you can find an example of using iteration and x-if="{{...}}​ in the link from my previous post.​

              Personally, I checked for notEqual and equal:

              Code:
              <table style="border: 1pt; border-spacing: 1pt; border-collapse: collapse; width: 100%;" cellpadding="4" border="3pt"><tbody>
                    <tr>
                      <th width="35%" align="left">Name</th>
                      <th width="35%" align="left">Contact Number</th>
                      <th width="30%" align="left">Email</th>
                    </tr>
                    <tr x-if="{{notEqual emailAddress null}}" iterate="{{contacts}}">
                      <td>{{name}}</td>
                      <td>{{phoneNumber}}</td>
                      <td>{{emailAddress}}</td>
                    </tr>
                    <tr x-if="{{equal emailAddress null}}" iterate="{{contacts}}">
                      <td>nothing1</td>
                      <td>nothing2</td>
                      <td>nothing3</td>
                    </tr>
                  </tbody>
              </table>​​
              Click image for larger version  Name:	image.png Views:	0 Size:	10.4 KB ID:	117697

              Click image for larger version  Name:	image.png Views:	0 Size:	17.1 KB ID:	117696
              Last edited by victor; Today, 02:51 PM.

              Comment

              Working...