Platform
Templates
Referencing data

Referencing data in templates

Documentation outlining how to work with data in your templates.

In addition to the variables available as part of the workflow run scope, you can also reference data from the users, objects, tenants, and subscriptions that exist within your Knock environment.

Referencing data is a powerful way to share context across entities in your templates without needing to manually pass the data in the data argument of your workflow trigger.

Referencing users via the user filter

#

To reference a user, you can use the user filter. This will return a serialized User, which you can then use to output data in your template.

Users returned will have all custom properties available, as well as the id, name, email, phone_number, created_at, and updated_at properties.


Referencing objects via the object filter

#

To reference an object, you can use the object filter. This will return a serialized Object, which you can then use to output data in your template. When referencing an object, you'll also need to specify the collection of the object you're loading.

Objects returned will have all custom properties available, as well as the id, collection, created_at, and updated_at properties. Read more about working with objects.


Referencing tenants via the tenant filter

#

To reference a tenant, you can use the tenant filter. This will return a serialized Tenant, which you can then use to output data in your template.

Tenants returned will have all custom properties available, as well as the id, created_at, and updated_at properties. Read more about working with tenants.


Referencing subscriptions via the subscriptions filter

#

To reference the subscriptions for a user, you can use the subscriptions filter. This filter loads up to 25 active subscriptions for the given user and returns a list of serialized subscription objects.

Each subscription returned includes the object the user is subscribed to, along with any custom properties set on the subscription. You can iterate over the results to render subscription-specific content in your templates.


Frequently asked questions

#

If you reference a user, object, or tenant that doesn't exist, the value will be null in your template. Trying to use it to output data will return an empty string.

If you want to conditionally display data based on whether a user, object, or tenant exists, you can do so using Liquid's if statement.

Knock cannot constrain the entities that are available in your template based on the recipient of the workflow run or the tenant passed in. It is your responsibility to ensure that any entities loaded as part of executing a template are accessible to the recipient.

New chat