Liquid templates

Liquid is an open-source template language, originally created by Shopify and now used by many other apps.

In Userflow, Liquid templates are used in a few places to allow for highly custom logic. Liquid templates can generate dynamic values, based on user attributes, the current page, and control flow statements such as if and case/when.

Example use cases:

  • An AI Assistant 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

Userflow context variables

When Liquid templates are rendered, e.g. when the instructions for the AI Assistant is being 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

Contains the URL of the page the user is currently on, if the template is used in the context of an actively visiting user.

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.

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 }}

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 the URL pattern matching guide.

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_flows %}
  flows
{% elsif is_themes %}
  themes
{% else %}
  fallback value
{% endif %}

Got questions? We're here for you!

The best way to get help is to
We usually reply within 5 minutes
You can also send an email to support@userflow.com
We usually reply within a few hours