Skip to content

Customizing Standard Templates

A standard template takes the content of the PDF from two places:

  • The template record holds texts, labels, switches and formats. You change them in the record fields, without touching any code.
  • The Liquid file attached to the template defines structure, appearance and fixed content – which blocks and which template fields are printed in which order, the columns of the invoice line item table, the default texts of the labels, the logo, fonts, colors and page layout.

A template field takes effect only if the Liquid file reads it. So before you change a standard template, check which of the two holds what you want to change. Some content that a classic template takes from template fields – for example, the header, the info blocks, the addresses or custom CSS – is part of the Liquid file on a standard template.

This article covers the following tasks:

For the basic setup of a standard template, see Configuring Standard Templates. For working with Liquid code in general – debug mode, filters, fonts and images – see Working With Liquid Code.

Locating Relevant Configuration

The following table shows where to make a change when you use the Liquid file that JustOn Billing & Invoice Management delivers. For a field-by-field list, see Standard Template Field Usage.

To change ... Edit ...
greeting, printed below the invoice header, before the opening sentence Text 1
free text below the invoice line item table Text 3
closing text, printed last, before the company signature Text 2
footer text, printed at the bottom of each page Footer
footer position, font and color Liquid file, CSS class page-footer
page header, page counter Liquid file, @page rule in the <style> block
The counter text Page x of y is fixed in the Liquid file and cannot be translated using override labels.
tax summary table and its introduction text Tax Table, Tax Table Text
reverse charge notices Reverse Charge Text, Reverse Charge Text EU, Tax Information Non-EU
introduction text of the installments table Installments Text
outstanding invoices list and its introduction text Outstanding Invoices, Outstanding Invoices Text
A value in the Outstanding Invoices Text field of the invoice takes precedence.
payment information text Payment Info fields, see Configuring Payment Information Texts
date format Date Format
number and currency format PDF Options, see Adjusting PDF Options
subtotal, discount and tax labels, early payment discount sentence the dedicated label fields, see Localized Labels
They take precedence over override labels.
all other fixed labels – letter head, table headers, bank details, document type Override Labels, see Using Override Labels on Standard Templates
labels for one invoice type only, for example, cancellations Override Labels on the template detail of the invoice type, see Configuring Template Details
Template details do not change Text 1, Text 2 and Text 3 on a standard template.
grouping of line items into sections and subtotals Category Criterion, Category Label, Subtotal Criterion, No Subtotal Tax, No Subtotal Discount
shipping and handling fees in the invoice line item table Liquid file, see Printing Shipping and Handling Fees
columns of the invoice line item table Liquid file, see Adding Field to Invoice Line Item Table
logo Liquid file, an <img> element in the invoice header block, see Images
fonts, font sizes, colors, margins, page size Liquid file, <style> block
draft watermark Liquid file, CSS class watermark

Note

The delivered Liquid file does not read the following template fields: Custom CSS, Header, Info Left, Info Right, Page Header, Table Columns and the address fields. Neither does it use the logo file attached as Template Logo. For the complete list, see Fields Not Used.

A customized Liquid file can read any field of the template, including custom fields, see Using JustOn Template Fields.

Adding Field to Invoice Line Item Table

Every field of the Invoice Line Item object that the user creating the PDF can read is available in the Liquid file, with no further configuration. Fields of related records, like the item or the subscription, are not available on the line item.

The following steps refer to the Liquid file that JustOn Billing & Invoice Management delivers, in which the columns are written into the file. If your Liquid file has been customized, its line item table may be structured differently. The example adds the custom field CostCenter__c.

A field is available as row.lineItem.<field>. Write the API name in lowercase and without the namespace prefix – row.lineItem.unit__c, not row.lineItem.ONB2__Unit__c. Custom fields you have created yourself have no namespace prefix anyway.

To add a column next to the description:

  1. Find the API name of the field in the data structure.

    Open an invoice in the Liquid template debug mode with the URL parameter &debug=data, and look up the field in one of the lineItem entries of invoiceTable.

  2. In the Liquid file, add a header cell to the table header.

    The table header is the <tr class="line-item-header"> element. Add the new <th> element at the position where the column is to appear:

    <th class="header-title">{{ labels['lineItemsTable.title'] | default: 'Title' }}</th>
    <th>{{ labels['lineItemsTable.costCenter'] | default: 'Cost Center' }}</th>
    

    For the column label, you can write a literal text, or read a label key with a fallback as shown here. To translate a label key, add it to the override labels of the template, see Using Override Labels on Standard Templates.

  3. Add a data cell at the same position in the line item row.

    The line item row is the <tr class="line-item-row"> element. Add the new <td> element after the cell with the description:

    <td class="table-cost-center"><div>{{ row.lineItem.costcenter__c }}</div></td>
    
  4. Adjust the column span of the subtotal and total rows.

    These rows span the table width with a calculated column span. Increase both values by one for each column you add:

    {% if hasdiscount %}
      {% assign invoice_colspan = 7 %}
    {% else %}
      {% assign invoice_colspan = 6 %}
    {% endif %}
    

    On final invoices, the title row of the received payments block uses a fixed column span (colspan="7"). Increase it as well.

  5. Upload the edited file to the template and check the result.

    For uploading the file, see Attaching a Liquid File. Then create the PDF for a draft invoice and make sure that the new column is printed and that the subtotal and total rows are aligned.

Info

To format the value of a number, currency or date field, use the filters the other columns use – for example, {{ row.lineItem.myamount__c | currency }} or {{ row.lineItem.mydate__c | date: dateFormat }}. For details, see Using Custom Liquid Filters.

Printing Shipping and Handling Fees

As of v2.123, the Liquid file that JustOn Billing & Invoice Management delivers prints line items of the type Shipping Fees and Handling Fees: one row per fee with its title and net amount, followed by the tax of the fees per tax rate – like a classic template. On final invoices, the tax of the fees is also listed in the remaining amount block.

The tax rows of the fees are printed separately from the tax rows of the products, so a tax rate can appear twice – once for the products and once for the fees. The fee rows use the labels of the line item table: the title of the fee line item, and the tax label from the Tax Label field or the override label totals.tax.

A Liquid file that was attached to a template before v2.122 does not print the fees, although their amounts are included in the grand total. As a result, the printed line items do not add up to the grand total. To print the fees, add the code of the current delivered Liquid file to the attached file:

  1. In the Liquid file, find the comment <!-- Display the grand total for non final invoice: -->.

    It follows the loop over the rows of the line item table, directly before the grand total row.

  2. Insert the following code directly before this comment:

    {% for feeSection in invoiceTable %}
      {% if feeSection.section == 'Detail:Shipping Fees' or feeSection.section == 'Detail:Handling Fees' %}
        {% for feeRow in feeSection.rows %}
          {% if feeRow.lineItem %}
            <tr class="fee-row">
              <td></td>
              <td colspan="{{ invoice_colspan }}">{{ feeRow.lineItem.title__c }}</td>
              <td>{{ feeRow.lineItem.postotalnet__c | currency }}</td>
            </tr>
          {% endif %}
          {% if feeRow.subtotalType == 'subtotalTax' %}
            <tr class="subtotal-tax fee-tax">
              <td></td>
              {% assign _feeTaxRatePct = feeRow.taxRate | percent %}
              {% assign _feeTaxLbl = labels['totals.tax'] | default: 'Tax ({rate})' %}
              <td colspan="{{ invoice_colspan }}">{{ _feeTaxLbl | replace: '{rate}', _feeTaxRatePct }}</td>
              <td>{{ feeRow.subtotal.subtotalTax | currency }}</td>
            </tr>
          {% endif %}
        {% endfor %}
      {% endif %}
    {% endfor %}
    
  3. For final invoices, find the row <tr class="remaining-amount-gross"> in the remaining amount block.

    It follows the loop that prints the remaining tax per tax rate.

  4. Insert the following code directly before this row:

    {% for feeSection in invoiceTable %}
      {% if feeSection.section == 'Detail:Shipping Fees' or feeSection.section == 'Detail:Handling Fees' %}
        {% for feeRow in feeSection.rows %}
          {% if feeRow.subtotalType == 'subtotalTax' %}
            <tr class="subtotalTax fee-tax">
              <td></td>
              {% assign _remFeeTaxPct = feeRow.taxRate | percent %}
              {% assign _remFeeTaxLbl = labels['totals.tax'] | default: 'Tax ({rate})' %}
              <td colspan="4">{{ _remFeeTaxLbl | replace: '{rate}', _remFeeTaxPct }}</td>
              <td>{{ feeRow.subtotal.subtotalTax | currency }}</td>
            </tr>
          {% endif %}
        {% endfor %}
      {% endif %}
    {% endfor %}
    
  5. Upload the edited file to the template, see Attaching a Liquid File.

  6. Create the PDF for a draft invoice with a shipping fee and check that the printed rows add up to the grand total.

Alternatively, create a new template using New, which attaches the current delivered file, and transfer your changes to it, see Keeping Changes Across Upgrades.

Info

The fee rows before the grand total use the column span of the subtotal rows. If you have added columns to the table as described in Adding Field to Invoice Line Item Table, they adapt automatically. The rows of the remaining amount block use a fixed column span, like the other rows of this block.

Using Override Labels on Standard Templates

The Override Labels field of a standard template translates the fixed labels of the PDF, like the column headers or the document type heading. A standard template reads only the v3 block of the field:

{
    "v3": {
        "lineItemsTable.quantity": "Menge",
        "lineItemsTable.costCenter": "Kostenstelle"
    }
}

The field is not a general label override like the override labels of classic templates:

  • The Liquid file reads a fixed set of keys. The delivered file reads the keys listed in Override Labels.
  • You can add any other key, but it has no effect until the Liquid file reads it – like the key lineItemsTable.costCenter in the example above.
  • Field labels from Salesforce are not used. To label a column you add, write the label into the Liquid file or read your own key.

A key that is missing from the field falls back to the default text written in the Liquid file. For the labels that have a dedicated template field, the field value takes precedence over the key.

To use different labels for one invoice type, you specify the Override Labels field on the template detail for this type:

  1. Open the template and copy the complete value of the Override Labels field.
  2. In the Template Details section, click Edit in the row of the template detail for the invoice type, for example, Cancelation.

    If there is no template detail for this type yet, create one, see Creating New Template Detail.

  3. Paste the copied value into the Override Labels field.

  4. Change the keys you need.

    Modify, for example, messages.cancelRelated for the opening sentence of cancellations, or messages.credit for the opening sentence of credits without related invoice.

  5. Click Save.

Note

The Override Labels value of a template detail replaces the value of the template as a whole – the two are not merged. Keys that are missing from the template detail fall back to the defaults of the Liquid file, not to the template. That is why you start from the complete value of the template.

Keeping Changes Across Upgrades

The Liquid file attached to a template is a copy of the delivered file, created when the template is created. Package upgrades of JustOn Billing & Invoice Management do not change attached Liquid files. You can therefore edit the attached file directly – your changes are kept when you upgrade.

This also means that improvements to the delivered Liquid file in a later version do not reach your existing templates. To use them, create a new template using New, which attaches the current delivered file, and transfer your changes to it.

Info

Before you edit a Liquid file, download it and keep the original as a backup.