Skip to content

Developers · Liquid

Liquid Tags: Insites

Last updated 5 November 2026

background

Invokes code within the tag asynchronously, in the background. You will only have access to variables you explicitly pass to the background tag. The context object is available by default, but with limitations - you need to explicitly pass page/layout metadata if you want to use it, as well as device and constants.

Params

NameTypeDescription
optionsHashAny variable provided to the background tag will become accessible in the code.
options.delayFloatWhich defines the number of minutes to delay running code (defaults to 0, which means run code as soon as possible).
options.priorityStringlow, default or high. See the AsyncCallbackPriority enum.
options.max_attemptsIntegerThe number of times to re-try a job upon failing. Default is 1, maximum is 5.
options.source_nameStringYour label of the job to help you identify it.

Examples

The following code will run all the log queries in the background, not earlier than 0.5 minute (30 seconds) since the execution. You will only have access to variables
explicitly provided to the background tag: "data" and "hey". Note that you will not have access to the "my_data" variable. Also note
that the result of this background tag will not be rendered, and you will not have access to any variable inside the background tag.

{% assign my_data = { "hello": "world" } %}
{% assign not_available_in_background = "You will not see me" %}
{% background priority: "low", delay: 0.5, max_attempts: 3, source_name: "my custom job", data: my_data, hey: "hello" %}
  {% log not_available_in_background %} {% comment %}Will be null, as this variable was not passed to the background tag {% endcomment %}
  {% log data %} {% comment %}You will see { "hello": "world" }, as it was provided to the background tag{% endcomment %}
  {% log hey %} {% comment %}You will see "hello" as it was provided to the background tag{% endcomment %}
  {% log context %} {% comment %}You will copy the current request context and make it available in the background{% endcomment %}
  {% assign not_available_outside = "You will not see me" %}
  {{ not_available_outside }} {% comment %}This variable will be rendered in the background, meaning you won't see anything on the page{% endcomment %}
{% endbackground %}
{{ not_available_outside }} {% comment %}This will be blank, because the assign will happen in the background - you won't have access to it here{% endcomment %}

cache

Checks if there's a string cached for the given key. If yes, it just returns the value without processing anything inside the cache tag, otherwise, it executes code, and stores the result in the cache. When you hit the page with such code for the first time, the code will be executed and hence it will iterate through the loop and generate random strings. However, then the result of the block will be cached and all the following requests within 20 seconds would not invoke the code - instead, it would just take the value from the cache. The output will not change. When the cache expires, the code will be evaluated again, producing another set of random strings. The cache is automatically invalidated if any changes are applied to any view/translation.

Params

NameTypeDescription
keyStringThe key which should uniquely identify the cached fragment.
expireIntegerOptional. The number of seconds since populating the cache to expiration.

Examples

{% cache "this is my key", expire: 20 %}

    {% for i in (1..100) %}
      {{ 18 | random_string }}
    {% endfor %}

{% endcache %}
{%- capture pagesUpdatedAtJson -%}
  {%- cache pagesUpdatedAtCache -%}
    {%- graphql g = "pages_updated_at" | hash_dig: "admin_pages", "results" -%}
    {{- g | json -}}
  {%- endcache -%}
{%- endcapture -%}
{%- assign pagesUpdatedAt = pagesUpdatedAtJson | parse_json -%}
{%- export pagesUpdatedAt, namespace: "nav" -%}

content_for

Stores a block of markup in an identifier for later use. Render it later with yield tag.

Params

NameTypeDescription
nameStringThe markups will be stored under this name.
flushBooleanOptional. If the flush parameter is true content_for replaces the blocks it is given instead of appending content to the existing one.

Examples

{% content_for "header" %}
  Hello world
{% endcontent_for %}

context

Set locale in context to a given language.

Params

NameTypeDescription
languageStringLanguage 2 letter.

Examples

{% context language: "de" %}

export

Makes variables defined inside partial accessible anywhere via context.exports.`namespace`

Params

NameTypeDescription
variableAnyVariable to be stored inside the namespace.
namespaceStringNamespace under which variable will be in context.exports.

Examples

{% liquid
  assign a = "value for a"
  assign b = "value for b"
  export a, b, namespace: "my_hash"
%}

{{ context.exports.my_hash }} => { "a": "value for a", "b": "value for b" }
{% assign company = {
  "name": "Insites",
  "technologies": ["liquid", "graphql"],
  "countries": { "USA": 5, "Poland": 5, "Romania": 2 }
} %}

{% export company, namespace: "data" %}

{{ context.exports.data }} =>
  {"company"=>{"name"=>"Insites", "technologies"=>["liquid", "graphql"], "countries"=>{"USA"=>5, "Poland"=>5, "Romania"=>2}}}
{{ context.exports.data.company.technologies }} => liquidgraphql
{{ context.exports.data.company.name }} => Insites

form

Generates an HTML form element for a resource. Use it inside a form file in the app/forms directory. Inside the tag you can use the `form_builder` variable.

Params

NameTypeDescription
html-idStringSets the id attribute on the <form> element.
html-novalidateStringAdds the novalidate attribute to the <form> element.
html-classStringAdds a CSS class to the <form> element.
html-multipartBooleanAdds enctype='multipart/form-data' to the <form> element. Multipart is enabled by default.
html-data-attr[String] Adds a data attribute to the <form> element, for example html-data-user-id adds data-user-id.

Examples

{% form %}
  {{ form_builder }}
{% endform %}
{% form html-id: "someid", html-novalidate: true, html-class: "big-form green-form", html-data-user-id: "12345", html-multipart: false %}
{% endform %}

function

Allows to store a variable returned by a partial. Partial needs to return data with `return` tag. All variables needs to be passed explicitly to function. Variables from upper scope are not visible in function. *Note:* `context` is not available inside the function partial unless explicitly passed as a variable.

Examples

{% function res = "path/to/my/partial", arg1: "hello" %}
# path/to/my/partial
{% liquid
  assign res = "hello" | append: foo | append: " " | append: context.location.host
  return res
%}
# path/to/my/partial

{% liquid
  assign foo = "hello"
  function res = "path/to/my/partial", foo: foo, context: context
%}

graphql

Executes a GraphQL query stored in a file, or a GraphQL query written inline. All arguments provided to the tag will be passed to GraphQL. It returns a hash with the data or the errors that occurred (for example, variable type mismatch, required variable not provided, syntax error) etc.

Params

NameTypeDescription
query_nameStringName of the GraphQL query. For get_users.graphql file name of the query is get_users
argumentsHashOptional. key:value pair(s) which will be passed to GraphQL query. For example, if your query looks like `query my_query($email: String!)`, then you can provide `email: "[email protected]"`
argsHash|JSONOptional. Either a Hash or a String of the arguments which will be passed to GraphQL query. See examples below.

Examples

Invoke query "get_records" and store the result in variable "g":
{% graphql g = "get_records", record_id: context.params.slug2 %}
Chain filters to extract results in one line:
{% graphql g = "get_records", record_id: context.params.slug2 | hash_fetch: "records" | hash_fetch: "results" %}
Pass all arguments at once as a hash to have graphql tag in one line and/or compose arguments hash dynamically:
{% assign arguments = {
  "record_id": context.params.slug2,
  "user_id": context.params.user_id
} %}

{% graphql g = "get_records", args: arguments %}
Pass all arguments at once as a JSON string:

{% capture arguments %}
{
   "per_page": 20,
   "page": 2
}
{% endcapture %}

{% graphql g = "get_records", args: arguments %}
Invoke inline query and store the result in variable "g". This is recommended for one-time used queries.

{% graphql g, id: context.params.slug2, message: "new message" %}
  mutation set_message($id: ID!, $message: String!) {
    record_update(
      id: $id
      record: {
        table: "message"
        properties: [{ name: "message", value: $message }]
      }
    ) {
      id
      message: property(name: "message")
    }
  }
{% endgraphql %}

include_form

This tag should be used to render forms defined in forms directory.

Params

NameTypeDescription
form_nameStringName of the form in the forms directory.
idIDID of the resource you want to edit.
parent_resource_idStringName of the resource type, i.e. name of custom_model_type, transactable_type, user_profile_type.

Examples

{% include_form "signup_form" %}
{% include_form "edit_user", id: user.id %}
{% include_form "manager_invite_to_interview", parent_resource_id: "invitation", user: g.user %}

log

Prints information to the instance logs. To view logs, run in your project folder and open http://localhost:3030/logs. To see logs in the terminal, run .

Params

NameTypeDescription
messageAnyAny object that can be printed.
typeStringType of log entry. Use it to tag your logs to make it easier to differentiate logs. If you set it to 'error' insites-cli will also notify your OS about it if your OS supports it.
envStringEnvironment where the entry should be created; can be any of 'all', 'staging', 'production'. Default: 'all'

Examples

{% log "hello world" %}
{% log params, type: "request-params" %}
{% log user.id, type: "debug" %}
{% log context.current_user, type: "error" %}
{% log context.current_user, type: "error", env: "staging" %}

parse_json

Parses a JSON string into a hash or array. Use it for a JSON string that arrives at runtime, such as an API response body. For JSON you write in the template, use an assign literal: .

To parse a string you already hold in a variable, use the parse_json filter: {% assign data = response_body | parse_json %}.

Examples

{% assign data = response.body | parse_json %}
{{ data.id }}
{% assign car = { "type": "SUV", "gearbox": "AT" } %}

{{ car }} => {"type"=>"SUV", "gearbox"=>"AT"}
{{ car.type }} => SUV
{% assign cars = [
  { "maker": "Honda", "model": "CRX" },
  { "maker": "Subaru", "model": "Forester" },
  { "maker": "Lexus", "model": "LFA" }
] %}
{% assign color = "red" %}
{% assign car = 'Mazda "5"' %}
{% assign data = { "color": color, "car": car, "nested": { "price": 100 } } %}

{{ data }} => {"color":"red","car":"Mazda \"5\"","nested":{"price":100}}

print

Print variable, skipping any additional sanitization. It provides a way to display a variable which consists of both safe and unsafe html. Warning: Do not use it with data entered by users as it is gonna cause XSS.

Params

NameTypeDescription
variableStringA variable containing safe and potentially unsafe HTML.

Examples

{% liquid
  assign invokable_script = '<script>alert("I will be executed")</script>'
  assign malicious_script = '<script>alert("I should be escaped")</script>'
%}
{% capture result %}
  {{ malicious_script }}{{ invokable_script | html_safe }}
{% endcapture %}
{% print result %}

redirect_to

Redirects browser to target

Params

NameTypeDescription
targetString
Path or url.
statusInt3xx HTTP code, default 302.

Examples

{% redirect_to "/dashboard" %}
{% redirect_to "https://example.com/signup" %}
{% redirect_to "/dashboard", status: 301 %}

response_headers

Allows you to set additional HTTP headers for the response.

Params

NameTypeDescription
headersStringHeaders as JSON string, default {}.

Examples

{% response_headers '{"foo": "bar"}' %}
{% response_headers '{"Content-Type": "application/json", "X-Frame-Options": "somevalue"}' %}

response_status

Allows you to set HTTP status for the response. Default 200.

Params

NameTypeDescription
statusIntHTTP status, default 200

Examples

{% response_status 204 %}
{% response_status 404 %}

return

Used inside a partial invoked by a function tag to return a variable.

Examples

{% liquid
  assign result = 1 | plus: 3
  return result
%}

session

Stores data during user's session Sets field of given name to given value in context.session.

Examples

{% session foo = "bar" %}
{{ context.session | json }} => { "foo": "bar" }
{% assign bar = "42" %}
{% session foo = bar %}
{{ context.session | json }} => { "foo": "42" }
{% session foo = null %}
{{ context.session | json }} => {}
{% session foo = blank %}
{{ context.session | json }} => {}

sign_in

Sign in user.

Params

NameTypeDefinition
user_idStringuser id

Examples

{% sign_in user_id: "12345" %}

spam_protection

Generates HTML for spam protection. Supports three strategies: recaptcha_v2 and recaptcha_v3 (Google reCAPTCHA) and hcaptcha (hCaptcha).

Params

NameTypeDescription
strategyStringName of protection strategy. Default is recaptcha_v2.
actionStringAction name for reCAPTCHA V3, action may only contain alphanumeric characters and slashes

Examples

{% form %}
  {% spam_protection "recaptcha_v2" %}
{% endform %}
{% form %}
  {% spam_protection "recaptcha_v3", action: "signup" %}
{% endform %}
{% form %}
  {% spam_protection "hcaptcha" %}
{% endform %}

theme_render_rc

Lets you set search paths for theme partials with the theme_search_paths property in app/config.yml. For example:

theme_search_paths:
  - theme/{{ context.constants.MY_THEME | default: "custom" }}
  - theme/simple

Examples

When you render a partial using theme_render

{% theme_render_rc "product" %}

The system will try to render theme/custom/product, and if it does not exist, it will fallback to theme/simple/product (if it also does not exist, the missing partial error is raised)

transaction

Runs all database writes inside the block as one transaction. If one fails, all are rolled back. The timeout parameter (in seconds) aborts and rolls back a block that runs too long. Variables inside and outside the block are shared. A background job scheduled inside the block is queued only after the transaction commits.

Params

NameTypeDescription
timeoutIntegerOptional. Number of seconds before the block is aborted and rolled back.

Examples

{% transaction timeout: 5 %}
  {% graphql order = "orders/create", data: order_data %}
  {% if order.errors %}
    {% rollback %}
  {% endif %}
{% endtransaction %}

rollback

Rolls back the current transaction by hand. Use it inside a transaction block.

Examples

{% liquid
  transaction
    graphql order = "orders/create", data: order_data
    if order.errors
      rollback
    endif
  endtransaction
%}

try

Catches errors. This is most useful with in app/config.yml.

Examples

{% liquid
  try
    include template_path
  catch err
    unless err.message contains "can't find partial"
      log err, type: "error when including template file"
    endunless
    include fallback_template_path
  endtry
%}

yield

Execute code wrapped inside content_for

Params

NameTypeDescription
nameStringName of content_for block.

Examples

Use this in a liquid view first. Then you can use yield inside the layout (for example) or another subsequently rendered view, like below:
{% content_for "greeting" %}Hello world{% endcontent_for %}

# another_file.liquid
{% yield "greeting" %}