No announcement yet.

if condition in PDF templates

  • Filter
  • Time
  • Show
Clear All
new posts

  • if condition in PDF templates

    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 I hope it will help you.


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


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


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


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


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


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


              You might get result like these:

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


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

                {{#each assets}} {{#ifEqual assetType "Bank Account"}}{{name}}
                Bank Code: {{accountBankCode}}
                Account Number: {{accountNumber}}
                {{#ifEqual assetType "Car"}}
                Plate Number: {{assetMainCode}}
                {{/ifEqual}} {{/ifEqual}}
                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.

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


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


                  • #11
                    PHP Code:
                    <!-- {{#each payrollItems}} -->
                    <!-- {{#ifEqual type 'Refact'}} -->
                    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>
                    <!-- {{/
                    ifEqual}} -->
                    <!-- {{/
                    each}} -->​ 
                    in you case :

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


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


                      • #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" ;="">


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



                          • #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="" style="float:left"></a></p>