back to knowledgebase

Advanced PDF Features to enable conditional data output

Updated: 23 May 2022 15:24:12 OpenCRM::Settings

We recommend that you have some working knowledge of HTML and/or CSS before attempting this. If you do not, please get in touch with our support team who will be able to help.

Accessing the HTML of PDF templates

Just as with email templates, PDF templates in OpenCRM can be designed using the WYSIWYG Editor, or by selecting Source and editing the HTML. This can be done for both Header and Footer sections.

The following functions need to be created and edited in the HTML of the PDF template, and so require a certain level of familiarity with HTML. As with all templates, we advise that you save a copy of a template to edit - if for any reason the results are not what you expect, you have your original document to fall back on.


 

PDF template functions user documentation

The PDF template functions can be seen as an extension to the merge variables. They are functions that can be used to control the output based on the content of a merge variable or multiple merge variables.

The following function is an example of a a PDF template function which adds

"Dear $contactdetails_contactname"

to the pdf template if $contactdetails_contactname contains a value.

IFFIELD[$contactdetails_contactname][notempty]
Dear $contactdetails_contactname
ENDIF

 

With this function you can conditionally include any html or merge variables as well as check multiple variables at the same time. The following example demonstrates multiple merge variables being checked and if all the variables contain a value, a table is displayed:


IFFIELD[$contactdetails_contactname&][notempty]
Appointment with  
Dear $contactdetails_contactname Dear $contactdetails_contactname
Dear $contactdetails_contactname Dear $contactdetails_contactname
ENDIF
 

A step further would be to nest the functions, which essentially means having a function within a function.  

IFFIELD[$contactdetails_contactname&][notempty]
Appointment with  
Dear $contactdetails_contactname Dear $contactdetails_contactname
Dear $contactdetails_contactname Dear $contactdetails_contactname
ENDIF
 

Troubleshooting

It's important to bear in mind that the pdf functions work directly on the html code. So when adding a pdf template function it is usually best to add them in the 'source' rather than on the visual editor. In the image below, the code has been added to the visual editor and so will not work

The visual editor is liable to include additional formatting which breaks the syntax and as a result the pdf function does not work correctly.


The function appears to be written correctly in the visual editor

 

The source shows additional html has been added that breaks the syntax of the function

Rate This Article
  • 1 star
  • 2 star
  • 3 star
  • 4 star
  • 5 star
Feedback and Comments
captcha code  


You may also be interested in: