Using dot liquid within pdfMachine merge

- to format merge fields or create line items.

Liquid allows you to apply formatting, perform loops, conditionals etc based on the values from your datasource. The standard filters and tags are supported as mentioned in Liquid For Designers and DotLiquid For Designers.

Note: To use Liquid Templating Tags in the email body the email body editor must always be in "Source" mode. The "wysiwig" mode will not preserve the Liquid Tags.

Using filters to format merge fields

Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output tag {{ }} and are denoted by a pipe character |. eg

The capitalize filter will cause the contents of the "name" cell from the data source to be capitalized.

            Input:
                 
{{ name | capitalize }}
Output:
John Smith

Looping (line items) and Conditionals

Conditional output can be done using Liquid tags in a HTML template.

Looping through rows to make line items appear can be done using any of the following methods in a HTML template

Review the example profile showing how to loop through rows and create line items in a Word template here.

The repeat_row, repeat_par filters

repeat_row

Repeats the current table row. Works with HTML and Word templates. See an example.

repeat_par

For HTML documents, repeats the current LI or DIV blocks.
For Word documents, repeats the current paragraph.

This can be used when the "Rows to emails method" is set to "one or more rows generates an email", which has the effect of grouping the rows based on a merge field, usually the email address.

NOTE: you place the filter on one and only one data item in the row or paragraph you are repeating.

Note in the example the merge field names must be prefixed with "row."

repeat_row example

            Input:
                             
Name Amount
{{row.name | repeat_row}} {{row.amount}}
Output:
Name     Amount
Dave     1230
Dave     1000

repeat_par example

            Input:
                
Name: {{ row.name | repeat_par }}
Amount: {{ row.amount }}
Output:
Name: Dave
Amount: 1230
Name: Dave
Amount: 1000

These filters are a shortcut for the Liquid 'for' loop. Specifically, the Liquid tag "{% for row in _rows %}" is placed around the paragraph or row. The Liquid for loop does not work well for visual html editors when used around table rows, so this is the preferred option.

Liquid Tags - looping using the 'for' loop

Tags are the programming logic that tell templates what to do. Tags are wrapped in: {% %} characters.

            Input:
                {% for row in _rows %}
                    
Name: {{ row.name | repeat_par }}
Amount: {{ row.amount }}
{% endfor %} Output:
Name: Dave
Amount: 1230
Name: Dave
Amount: 1000
For an example of using the above in a template:
Click here to see an example HTML merge template using liquid.
Click here to see an example of the PDF generated.
When you install pdfMachine merge, a profile is setup with this demo invoice template, which you try out and customize to your requirements.

Review the example profile here to see how to set up a profile with line items using Javascript.

When using HTML templates, for best results you will need to set certain print options in Internet Explorer

  • Turn off Internet Explorer print headers and footers by File | Page Setup and change them all to "empty"
  • Turn on background colors for printing by File | Page Setup, tick "Print Background Colors and Images"

If you need help or more information on this feature please contact

Liquid Tags - conditionals

Tags are the programming logic that tell templates what to do. Tags are wrapped in: {% %} characters.

Liquid also contains tags which support conditionals i.e. if statements

eg. The following will only output if there is data in the "name" cell in the data source:

            Input:
                    {% if name != "" %}
                        Hello {{ name }}
                    {% endif %}
            Output:
                    Hello John