Announcement

Collapse
No announcement yet.

if condition in PDF templates

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

  • if condition in PDF templates

    Hi,
    I wanted to ask if there is a built in if condition that would take the values of an "Enum" field? So for example I would need it to show "yes" if the "Enum" field value is "yes", "no" if the "Enum" field value is "no" and "undecided" if the "Enum" field value is "Undecided"

  • #2
    Hi Mark,
    Please check this https://docs.espocrm.com/user-guide/...ition-checking. I hope it will help you.

    Comment


    • #3
      You must do this in code view in the PDF editor. I guess in your case you can use the ifEqual statement.

      Comment


      • #4
        this is exactly what I was searching for! I have one more question if I want to compare a certain field with a fixed value how do I write that value in the condition? For example
        <!-- {{#ifEqual price 40}} -->
        a is equal b
        <!-- {{/ifEqual}} -->
        this does not work for me, I also tried writing like that "40" and '40' , but it didn't work. The value in that field was 40

        Comment


        • #5
          If it is not working, probably it is not supported. I see here 2 possible workarounds:
          1. Create a new field that will store the comparable value and then use the standard condition <!-- {{#ifEqual a b}} -->
          2. Create your Custom helper for PDF template that allows you to do that https://docs.espocrm.com/development...custom-helper/.

          Comment


          • #6
            I did not test your condition but it should work. Did you empty your browser cache? Very often it helps after changing something to rebuild from Admin and clear the browser cache.

            Comment


            • shalmaxb
              shalmaxb commented
              Editing a comment
              and sometimes it helps to use another browser. Chrome (and Edge as based on Chrome also) sometimes behaves strange.

          • #7
            Thanks for the answers, I tried clearing the cache, rebuilding from admin panel, changing browsers, but unfortunately it did not work. However I later on tried using different field types, and it actually did work, so I guess for some reason the comparison did not work, when the field was currency for me.
            Last edited by Mark; 08-17-2020, 12:53 PM.

            Comment


            • #8
              If it currency it might have something to do with the way it is display/store.

              I would suggest printing the field as normal and see what it look like, then write the ifEqual condition based on those value. For example you would do a couple of these using variation of value:

              {{price}}

              You might get result like these:
              40.01
              $40.01
              40.01$
              40,01
              4,000.01

              Then you might notice that 40 is not correct but the code need to be: <!-- {{#ifEqual price 40.00}} -->

              Comment


              • #9
                Not sure if this is Off-topic or relevant. Anyway I finally learn how to use the {if} function. Here is my code if anyone want to use it somehow.

                Feature: Contact link to an Asset. I want to print out 2 special asset that most people (at least our client) have: Bank Account and a Car(s)

                I double chain the If code which rather than created multiple list which I also can do. Currently one issue I'm facing is too many blank lines which you guy can slowly figure it out yourself.

                With that said, here is the code:

                Code:
                {{#each assets}} {{#ifEqual assetType "Bank Account"}}{{name}}
                Bank Code: {{accountBankCode}}
                Account Number: {{accountNumber}}
                {{else}}
                {{#ifEqual assetType "Car"}}
                {{name}}
                Plate Number: {{assetMainCode}}
                {{else}}
                {{/ifEqual}} {{/ifEqual}}
                {{/each}}​
                EDIT: And I decide to create a single chain version which make it easier to read as follow and to prevent too much blank lines I change it to the following style.

                Code:
                {{#each assets}}{{#ifEqual assetType "Bank Account"}}{{name}}
                Bank Code: {{accountBankCode}} | Account Number: {{accountNumber}} {{else}} {{/ifEqual}} {{/each}}
                {{#each assets}} {{#ifEqual assetType "Car"}}
                {{name}}
                Plate Number: {{assetMainCode}} {{else}} {{/ifEqual}} {{/each}}​
                Last edited by espcrm; 10-29-2022, 06:49 AM.

                Comment


                • #10
                  Could some tell me if we can use the {{#ifEqual feature to hide an image? I want to mark invoices as paid with a paid stamp (PNG Image File) when status = Paid but cant seem to make it work

                  Comment


                  • #11
                    PHP Code:
                    <!-- {{#each payrollItems}} -->
                    <!-- {{#ifEqual type 'Refact'}} -->
                        
                    <tr>
                            <
                    td colspan="2" width="15%" style="background-color: rgb(198, 177, 28); color: #ffffff;">{{type}}</td>
                            <
                    td colspan="8" width="70%" style="background-color: rgb(198, 177, 28); color: #ffffff;">{{info}}</td>
                            <
                    td colspan="2" width="15%" style="background-color: #F5F2D9;text-align: right;"><b>{{amount}}</b></td>
                        </
                    tr>
                    <!-- {{/
                    ifEqual}} -->
                    <!-- {{/
                    each}} -->​ 
                    in you case :

                    <!-- {{#ifEqual status 'Paid'}} -->

                    Comment


                    • #12
                      UPDATE: I've made it work with the following code for text based labels. Im about to try with the image now. Will post if it works but in the mean time maybe this will help someone else


                      {{#ifEqual status "Paid In Full"}}

                      <p style="text-align: center; "><span style="font-size: 70px;"><font color="#6ba54a">PAID</font></span></p>
                      {{/ifEqual}}​

                      Comment


                      • #13
                        UPDATE 2: Finally got it! This is to be used with a image. In my case Im marking the invoice as "Paid" with a png stamp when the Invoice status = Paid In Full

                        {{#ifEqual status "Paid In Full"}}

                        <p style="text-align: center; "><img src="?entryPoint=attachment&amp;id=63aca2536586ffd e4" style="width: 119px" ;="">
                        {{/ifEqual}}​

                        Comment


                        • #14
                          I'd like to add a "OR" condition to this next.

                          I tried the below with no success so far

                          {{#ifEqual status "Outstanding" || status "Partially Paid"|| status "Past Due"}}

                          IMAGE URL

                          {{/ifEqual}}

                          Comment


                          • #15
                            UPDATE 3: I wasn't able t get the 'OR" condition working just yet but Im going to continue working on it. For now I have been able to get this to do what I need it to which is removing a "Pay Now" button when the balance = 0.00

                            <!--{{#ifNotEqual outstandingBalance "0.00"}}-->
                            <p><a href="{{associatedBrand.billingPortalURL}}#Invoice/view/{{id}}"><img alt="" src="https://i.ibb.co/2715bxh/pay-invoice.png" style="float:left"></a></p>
                            <!--{{/ifNotEqual}}-->​

                            Comment

                            Working...
                            X