Liquid templates let you add dynamic text and logic to some Userflow settings, such as Adoption Agent instructions and a Resource Center knowledge block's default search. A template can use the user's attributes, their company's attributes and the current page URL, and can branch with if and case/when.
Liquid is an open-source template language created by Shopify. This page covers the variables and filters Userflow adds.
Example use cases:
An Adoption Agent can be provided with instructions tailored to the user (e.g. a “company type” attribute).
A resource center’s knowledge block’s Default search query field can be used to perform a different search based e.g. on the current page, in order to make the right articles show up under Suggested articles.
See also official Liquid documentation
Where can I use Liquid in Userflow?
Liquid templates work in these Userflow fields:
Adoption Agent instructions
A Resource Center knowledge block's Default search query field
Embed code
Liquid doesn't work in flow step content. Text in speech bubbles, tooltips, modals and buttons isn't rendered as Liquid, so a Liquid code sample placed there won't run.
To show different steps to different users in a flow, use a step trigger with an Attribute condition and a Go to step action. To remember something a user did earlier in a flow, use a step trigger with a Set user attribute action. Both are covered in Flow builder basics.
Which variables can I use in a template?
When Liquid templates are rendered, for example when Adoption Agent instructions are used, they have access to a few built-in variables which provide information about the user.
You can add user/company attributes to your template by enclosing them in double curly braces.
page_url
The page_url Liquid variable contains the URL of the page the user is on when the template renders, if the template is used for a user who is actively visiting your app. It always holds the current page. It can't tell you which page the user was on earlier, for example during a previous step of a flow.
user
Contains an object with all the user’s attributes. Access a user attribute as:
{{ user.example_attribute }}group
Contains an object with all the user’s current company/group’s attributes. Access a company/group attribute as:
{{ group.example_attribute }}The term “group” is used here because it is the technical term we use for companies, just as you call userflow.group(companyId) in Userflow.js to associate a user with a company/group. See Configuring companies.
group_membership
Contains an object with all the attributes of the membership between the user and the current company/group. Access a membership attribute as:
{{ group_membership.example_attribute }}Why doesn't my true/false condition match?
When a template renders, attribute values come through as text. A boolean attribute holds the text "true" or "false", so compare it to a quoted value:
{% if user.is_trial == "true" %}
The user is on a free trial.
{% endif %}Writing == true or == false without quotes won't match, and the condition falls through silently.
Userflow custom filters
url_matches
<url> | url_matches: <pattern>Returns true if <url> matches the <pattern>.
We use the same rules as in our Current page conditions. See URL pattern matching.
Example:
page_url | url_matches: '/projects/:id'Will return true for https://example.com/projects/123 and false for https://example.com/dashboard.
If you want a template to return a single value based on multiple different URL patterns, you need to first assign the result of url_matches to a local variable, since Liquid does not support filters in if or case statements.
{% assign is_projects = page_url | url_matches: '/projects*' %}
{% assign is_themes = page_url | url_matches: '/themes*' %}
{% if is_projects %}
projects
{% elsif is_themes %}
themes
{% else %}
fallback value
{% endif %}