Skip to content

Liquid Templating ​

Espanso Dynamic Forms uses LiquidJS to process templates. Liquid is a simple yet powerful templating language originally created by Shopify.

You'll use Liquid syntax in the two sections of the form config:

  • template – to format final output
  • data – To set dynamic default values

You can also use Liquid in the --form-config path to dynamically select which form to load.

Example ​

Let's define simple form with a single text input field called myAwesomeFormField. When you submit the form, template will be rendered, using the value entered in myAwesomeFormField:

yaml
schema:
  type: object
  properties:
    myAwesomeFormField:
      type: string

uischema:
  type: VerticalLayout
  elements:
    - type: Control
      scope: '#/properties/myAwesomeFormField'

template: |
	You entered: {{ myAwesomeFormField }}
	Characters count: {{ myAwesomeFormField | size }}
	Word count: {{ myAwesomeFormField | split: ' ' | size }}
	It's uppercase now: {{ myAwesomeFormField | upcase }}

Let's say you entered "Hello world" in the form field; the output would be:

text
You entered: Hello world
Characters count: 11
Word count: 2
It's uppercase now: HELLO WORLD

Template Data Context ​

The template has access to all properties defined in the form's schema section. Each property becomes a variable in the template context, accessible by its name.

You can also access additional built-in objects like {{env}} for environment variables and {{clipboard}} for clipboard content.

Template Syntax ​

ConstructSyntaxPurposeExample
Variable Output{{ variable }}Insert variable value{{subject}}
Filters{{ variable | filter }}Transform values{{name | capitalize}}
Conditionals{% if condition %}...{% endif %}Conditional rendering{% if draft %}...{% endif %}
Loops{% for item in array %}...{% endfor %}Iterate over arrays{% for tag in tags %}...{% endfor %}

Tags ​

Tags control logic and flow within templates. They are enclosed in {% %}. For example:

liquid
{% if myAwesomeFormField == "Hello" %}
  You said hello!
{% else %}
  You didn't say hello.
{% endif %}

There are various tags available in Liquid, such as if, for, case, and more.

Objects ​

Object represent the output variables and data. They are enclosed in {{ }}. Objects can be simple values or more complex data structures.

For example, we can use an env object that's provided to all templates by Espanso Dynamic Forms:

liquid
{{ env.EDF_INSTALLATION_DIR }}

Environment variables

Learn more about them on the Environment variables page.

Filters ​

Filter modify the output of objects. They are applied using pipe symbol |. For example:

liquid
{{ myAwesomeFormField | downcase }}

You can chain multiple filters together:

liquid
{{ myAwesomeFormField | strip | upcase }}

Special Variables ​

In addition to form field values, these utility variables are always available:

VariableDescriptionExample
newlineA newline character (\n){{items | join: newline}}
tabA tab character (\t){{tab}}Item 1

These are useful when you need to insert whitespace characters that are difficult to type directly in YAML.

Custom Filters ​

Espanso Dynamic Forms provides these additional filters beyond standard Liquid:

FilterDescriptionExample
url_encodeURL-encode a string{{ query | url_encode }}
url_decodeURL-decode a string{{ encoded | url_decode }}
render_templateRender a template string with context{{ template | render_template: file }}

render_template Filter ​

This filter lets you render a Liquid template stored in a variable:

yml
{% for file in files %}
{{ myTemplate | render_template: file }}
{% endfor %}

The context object (file in this case) becomes available inside the templates. This is useful for dynamic templates like in Files form.

Debugging Templates ​

When building complex templates, it's helpful to see exactly what data you're working with.

Inspecting Data ​

Use the json filter to dump an entire object or variable as a JSON string:

liquid
{{ variable | json }}

Example: To see all available form data:

liquid
<pre>
{{ self | json }}
</pre>

Built-in `self` variable

self variable refers to the root data object in LiquidJS

Common Errors ​

  • Missing output: Check if variable name matches schema property exactly (case-sensitive).
  • Whitespace issues: Use {%- and -%} to strip whitespace from control tags.
  • Unexpected values: Use {{ variable | json }} to check if you're getting a string, number, or array.

Official Resources ​

  • Liquid documentation – Official documentation for Liquid templating language
  • LiquidJS – JavaScript implementation of Liquid that's used in Espanso Dynamic Forms