Help with conditionals and tables when try to print to pdf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skynext280
    Junior Member
    • Jun 2024
    • 11

    Help with conditionals and tables when try to print to pdf

    Hey all, I think I'm doing something wrong, because I'm trying to use the conditionals inside the html tags when I make a pdf template, that is, I have this code


    <table>
    <tbody>
    <tr>
    <td>one</td>
    <td>two</td>
    </tr>
    </tbody>
    </table>​​​


    And I check the value of a field on my entity called {{closed}} posible values "yes", "no".

    The problem is, I try to make a if inside table like

    <table>
    <tbody>
    <tr>
    {{#if closed "yes"}}
    <td>oke is yes</td>
    {{else}}
    <td>oke is no</td>
    </tr>
    </tbody>
    </table>​​​


    when I saved and try to check printing got wrong, so I open the template again and my code is like this

    {#if closed "yes"}}

    {{else}}


    <table>
    <tbody>
    <tr>
    <td>oke is yes</td>
    <td>oke is no</td>
    </tr>
    </tbody>
    </table>​​​


    The questions is, How can I put conditionals inside tables, also I try on other entity something like this



    <table style="width: 100%;">
    <tbody>
    <tr iterate="{{contacts}}">
    <td>{{name}}</td>
    <td>{{assignedUserName}}</td>
    </tr>
    <tr>
    {{#if closed "yes"}}
    <td>oke is yes</td>
    {{else}}
    <td>oke is no</td>
    </tr>
    </tbody>
    </table>

    and get the same result


    {{#if closed "yes"}}

    {{else}}

    <table style="width: 100%;">
    <tbody>
    <tr iterate="{{contacts}}">
    <td>{{name}}</td>
    <td>{{assignedUserName}}</td>
    </tr>
    <tr>

    <td>oke is yes</td>
    <td>oke is no</td>
    </tr>
    </tbody>
    </table>


    thx for ur help
  • shalmaxb
    Senior Member
    • Mar 2015
    • 1602

    #2
    the editor puts the condition to the top, but this does not matter. I guess your field "closed" is a bool? Then you must write {{#if closed 'true'}}. The values of bool are true or false.

    Comment

    • yuri
      Member
      • Mar 2014
      • 8438

      #3
      Moving conditional part inside the a TD tag wlll work. The requirement is a code being a valid HTML, otherwise the contenteditable will modify the code to be valid HTML
      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

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        try this as Yuri mentioned

        PHP Code:
        <table>
        <tbody>
        <tr>
        <td>
        {{#if closed "yes"}}
            oke is yes
        {{else}}
        oke is no
        {{/if}}
        </td>
        </tr>
        </tbody>
        </table>
        Rabii
        Web Dev

        Comment

        • skynext280
          Junior Member
          • Jun 2024
          • 11

          #5
          Hey all again, This works for me, as Yuri and rabii said, I must put the <td> tags and inside the conditional

          <td>
          {{#ifEqual closed "yes"}}
          oke is yes
          {{else}}
          oke is no
          {{/ifEqual }}
          </td>

          thx u all!

          Comment

          Working...