Request for assistance with a PDF template.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abidoss
    Senior Member
    • Mar 2023
    • 229

    Request for assistance with a PDF template.

    Hello friends, Please, it's my first time using the PDF model for an employment contract. Could someone assist me in displaying a field based on a condition?

    For example, I have an enumeration list containing: Expenses included and Expenses not included, and two fields named 'expenses' and 'no_expenses'. In my template, I want to display only the field that I have selected in the list. For instance, if I select Expenses, then print the 'expenses' field in the template.

    I haven't quite understood the documentation, and there doesn't seem to be an example. Thank you.
  • emillod
    Active Community Member
    • Apr 2017
    • 1405

    #2
    Hello abidoss
    you have two options. You can use conditions or you can use PHP to build template helpers. It'll be better to prepare more advanced condition logic.
    You can use this conditions in PDF to check whether value is set or not, but as far as i remember, you can't use it to check WHICH value is set.

    {{#if value}}
    {{value}}
    {{else}}
    No value
    {{/if}}​

    Comment

    • rabii
      Active Community Member
      • Jun 2016
      • 1250

      #3
      try this, change the enumField with the name of the enum field

      PHP Code:
      {{#ifEqual enumField 'Expenses included'}}
          {{expenses}}
      {{else}}
          {{no_expenses}}
      {{/ifEqual}}
      Rabii
      Web Dev

      Comment


      • emillod
        emillod commented
        Editing a comment
        Thank you!

      • rabii
        rabii commented
        Editing a comment
        you are welcome mate
    • abidoss
      Senior Member
      • Mar 2023
      • 229

      #4
      Something is off; it prints that with a question mark

      Attached Files

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #5
        i have just tested the code and it works, when you copy code from the form, it will add some weird character at the end of the code make sure you past code into code editor remove any extra characters and then past it to your instance.
        Rabii
        Web Dev

        Comment

        • yuri
          Member
          • Mar 2014
          • 8444

          #6
          Use triple braces: https://docs.espocrm.com/user-guide/...df/#text-field

          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

          • abidoss
            Senior Member
            • Mar 2023
            • 229

            #7
            Now, everything is working well. Thank you!

            Comment

            Working...