Skip to content
Start free

Tags and Filters

Open in ClaudeOpen in ChatGPT

Word templates use the Liquid template language, like HTML templates. Type the tags into the document in Word or in the template editor.

{{ }} inserts a value. The value keeps the formatting of the tag: if the tag is bold and red in Word, so is the value.

{{ name }}
{{ customer.address.city }}
{{ line_items[0].description }}

Line breaks in a value become line breaks in the document, and tabs become tabs.

Filters format a value before it’s inserted:

{{ name | upcase }}
{{ invoice_date | date: "%B %-d, %Y" }}
{{ total | currency }}
{{ "now" | in_time_zone: "America/New_York" | date: "%Y-%m-%d" }}

Word templates have the same filters as HTML templates.

Word templates support if, elsif, else, unless, case, for (with break, continue and the forloop variables), assign and comment. What a block covers depends on where its tags are:

  • In one paragraph, a block covers the text between its tags:

    Total: {{ total | currency }}{% if paid %} (paid){% endif %}
  • In different paragraphs, a block covers the whole paragraphs and tables from the paragraph with the opening tag to the paragraph with the closing tag:

    {% if notes %}
    Notes
    {{ notes }}
    {% endif %}

    A paragraph that holds only tags like {% if notes %} is removed from the document, so it doesn’t leave a blank line.

  • In different cells of one table row, a block repeats or hides that row. Put {% for %} in the first cell and {% endfor %} in the last cell to add a row for each item:

    DescriptionQtyPrice
    {% for item in line_items %}{{ item.description }}{{ item.quantity }}{{ item.price | currency }}{% endfor %}
  • In different rows of one table, a block covers those rows and the rows between them.

The same rules apply inside a table cell: a block whose tags are both in one cell repeats or hides only what’s in that cell, and leaves the row as it is.

A block can’t start in one place and end in another kind of place, for example start in a table cell and end in a paragraph after the table. The editor lists tags that can’t be placed, with where they are.

Picture tags insert a picture where the tag is. Each takes a field, and optional sizes such as "4cm", "30mm", "1.5in", "72pt" or "200px".

TagField typeOptionsSize when not given
{% image logo %}Imagewidth, height, scale_type, gravityThe image’s own size, made smaller to fit the page
{% signature signer_signature %}Signaturewidth, heightFits in 5 cm by 2 cm
{% initials signer_initials %}Initialswidth, heightFits in 2 cm by 1 cm
{% barcode order_number %}Barcodewidth, height, symbology1.5 cm high
{% qrcode payment_url %}Any textsize3 cm square
{% image logo height: "1.6cm" %}
{% signature signer_signature width: "6cm" %}
{% barcode order_number symbology: "ean_13" %}
{% qrcode payment_url size: "2.5cm" %}
  • With only width or only height, the picture keeps its proportions. With both, it fits in that box.

  • An image with both a width and a height can also fill the box or be stretched to it, as PDF image fields can:

    • scale_type: "fit" (the default): the image keeps its proportions and fits inside the box.
    • scale_type: "fill": the image keeps its proportions and covers the whole box. The parts outside the box are cut off, on the sides away from its gravity: NorthWest, North, NorthEast, West, Center (the default), East, SouthWest, South or SouthEast. For example, gravity: "North" keeps the top of the image.
    • scale_type: "stretch": the image is stretched to the box’s width and height.
    {% image photo width: "3cm" height: "4cm" scale_type: "fill" gravity: "North" %}

    The image is cut in the Word document, so the uploaded image is never changed.

  • A signature can be an image or a typed name with a typeface. Typed signatures are drawn in that typeface.

  • symbology is one of code_128 (the default), code_25, code_39, code_93, ean_13, ean_8, upc_a or pdf417.

  • A picture tag with a blank value inserts nothing.

A form field is a place in the document for a value that a signer fills in. When a submission has signature requests, a signer who’s given the field fills it in on the signing page. Anywhere else, it prints the field’s value from the data.

In the template editor, the toolbar’s Insert a form field menu (beside Insert a field) inserts one where the cursor is, so you don’t have to type its tag. Under Signer, choose who fills in the form fields you insert: one of the template’s signers, Sender when the submission’s data fills them in, or Unassigned to leave it to each field’s Signer setting. Manage signers… opens the list of signers. Then choose the kind of field. The new field gets a name of its own, such as tenant_signature, and inside a {% for %} loop it’s named after the loop’s variable.

Click in a form field’s tag, or in a signature or initials tag, to change its kind, field, signer, options and size in the right pane. The editor writes the tag for you. You can also type one, in the editor or in Word:

{% form_field tenant_name %}
{% form_field start_date, kind: date, width: 4cm %}
{% form_field plan, kind: dropdown, options: "Monthly, Yearly" %}
{% form_field billing, kind: radio, option: Card %} Card {% form_field billing, kind: radio, option: Invoice %} Invoice
{% form_field tenant_signature, kind: signature, role: tenant %}
{% form_field signed_on, kind: date_signed, role: tenant %}
OptionDescription
kindtext (the default), date, checkbox, radio (one button of a group), dropdown, signature, initials or date_signed, which DocSpring fills in with the date its signer signs
widthIts width, such as 6cm, 30mm, 1.5in, 72pt or 200px. The default depends on its kind: 6 cm for text and 5 cm for a signature
heightIts height. The default depends on its kind: 0.8 cm for text and 2 cm for a signature
optionsA drop-down’s options, separated by commas: options: "Monthly, Yearly"
optionWhat a radio button’s field holds when it’s chosen: option: Card. Required for a radio button
requiredtrue or false, whether its field is added as required. Default true, or false for a checkbox. A date_signed field is always added as optional, since DocSpring fills it in. After that, the field’s Required setting decides
roleThe key of the signer role that fills it in, or sender when the submission’s data fills it in

A form field needs a field on the template’s field list, which DocSpring adds when the document is saved. If you delete the field from the list, submissions and previews fail with a message that names it. A signer can also fill in a signature or initials tag’s field, at the tag’s width and height.

Radio buttons with the same field are one group, with a tag for each option: the signer chooses one, and without signers the button whose option is the field’s value is marked.

A checkbox and a radio button draw their own outline, ticked or not, so the document shows where they are. A text field has none: put it on a line or in a table cell of your own.

A signer’s text prints at the size and in the color of the text around the tag, so it reads as part of the document, and so do a checkbox’s outline and check and a radio button’s outline and dot. The rest comes from the template’s Field defaults (in its settings): the typeface, bold, uppercase, alignment and character spacing for text, the check’s character, and the date formats for dates and date_signed fields.

Inside a {% for room in rooms %} loop, name the field after the loop’s variable to give each item its own: {% form_field room.initials, kind: initials %}. In a signature request, a required form field that an {% if %} leaves out of the document fails the submission, so turn off the Required setting of one that the data can leave out (details). Changing a tag’s required doesn’t change a field that’s already on the list.

{% metadata reference %}
{% template name %}
{% template version %}

metadata inserts a value from the submission’s metadata. template inserts the template’s id, name, version or version_published_at.

DocSpring never produces a document that’s different from the template. These fail the submission with a message that says what to fix:

  • A tag that can’t be read or placed. The editor shows these as you edit.
  • A filter that doesn’t exist, or a value a filter or picture tag can’t use (for example, a barcode value that the symbology can’t encode).
  • A picture that can’t be read.
  • A document that takes more than 5 seconds to fill in, or more than 128 MB of memory on top of the size of its data. A {% for %} loop that repeats far more often than it needs to is the usual cause. Loops can repeat up to 100,000 times in total.