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

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

    #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; 05-13-2025, 11:12 AM.
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9617

    #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

    Comment

    • victor
      Active Community Member
      • Aug 2022
      • 1115

      #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
        Member
        • Apr 2025
        • 73

        #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
          EspoCRM product developer
          • Mar 2014
          • 9617

          #5
          What EspoCRM version? There was a bug a couple versions back that has been already fixed.

          Comment


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

          #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
            EspoCRM product developer
            • Mar 2014
            • 9617

            #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.

            Comment


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

            #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
              • 1115

              #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; 05-14-2025, 02:51 PM.

              Comment


              • arturkulik
                arturkulik commented
                Editing a comment
                Thank You for explanation
            • arturkulik
              Member
              • Apr 2025
              • 73

              #10
              Originally posted by victor
              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:


              is there any way to contain 3 'if' condition in one? now i need to triplicate <tr></tr> declaration for 3 separate conditions ( 3 out of 6)

              Comment


              • victor
                victor commented
                Editing a comment
                Currently, there is no such possibility.
            • yuri
              EspoCRM product developer
              • Mar 2014
              • 9617

              #11
              x-else won't be ever implemented. x-if is enough.

              Comment

              • arturkulik
                Member
                • Apr 2025
                • 73

                #12
                Originally posted by yuri
                x-else won't be ever implemented. x-if is enough.
                can we extend please x-if to:

                x-if="{{OR/AND (cond1)(cond2)(cond3).......}}

                Comment

              • arturkulik
                Member
                • Apr 2025
                • 73

                #13
                <tr x-if="{{(or(equal role 'role0')(equal role 'role1')(equal role 'role2') )}}" iterate="{{opportunities}}">

                IT's not working gives 500

                multi conditionas are not described for x-if, how should it look like?

                3 separate definitions for table row for any condition works

                <tr x-if="{{equal role 'role0'}}" iterate="{{opportunities}}">
                <tr x-if="{{equal role 'role1'}}" iterate="{{opportunities}}">
                <tr x-if="{{equal role 'role2'}}" iterate="{{opportunities}}">

                Comment

                • yuri
                  EspoCRM product developer
                  • Mar 2014
                  • 9617

                  #14
                  There was a bug particular with the OR operator. Fixed.

                  Explicit steps to reproduce the behavior: 0 or 0 Printed. Expected behavior Not printed.


                  Comment

                  • arturkulik
                    Member
                    • Apr 2025
                    • 73

                    #15
                    Originally posted by yuri
                    There was a bug particular with the OR operator. Fixed.

                    Explicit steps to reproduce the behavior: 0 or 0 Printed. Expected behavior Not printed.

                    Thank You

                    Comment

                    Working...