Liquid Tags: Insites

Last updated on June 18, 2024

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 AsyncCallbackPriorityEnum GraphQL Object.
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

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

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

context

Set locale in context to a given language.

Params

NameTypeDescription
languageStringLanguage 2 letter.

Examples

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

form

Used to generate a html form element for a resource. Use within `form configuration`. Inside the tag you can use `form_builder` variable.

Params

NameTypeDescription
html-idStringSet id attribute in `
` element.
html-novalidateStringAdd `novalidate` attribute to `` element.
html-classStringAdd css class `` element.
html-multipartBooleanAdd `enctype="multipart/form-data"` attribute to `lgt;form enctype="multipart/form-data">` element. Multipart is enabled by default.
html-data-attr[String] add data attribute to `` element.

Examples

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

graphql

Used to execute GraphQL query stored in a file or invoke GraphQL query 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: "my-email@example.com"`
argsHash|JSONOptional. Either a Hash or a String of the arguments which will be passed to GraphQL query. See examples below.

Examples

hash_assign

Allows to easily modify a Hash with a syntax same as assign tag.

Examples

include_form

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

Params

NameTypeDescription
form_nameStringName of the form configuration from 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

log

Print information to environment logs. To view logs run `insites-cli gui serve ` in your application directory and go to `http://localhost:3333/Logs`. If you prefer seeing logs in the terminal, run `insites-cli gui logs `.

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

parse_json

Captures and parses the JSON string inside of the opening and closing tags and assigns it to a variable.

Params

NameTypeDefinition
variable_nameStringThe variable name that will be used to assign contents after it is parsed.
contentStringValid JSON string to be assigned.

Examples

print

Print variable, skipping any additional sanitisation. 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

redirect_to

Redirects browser to target

Params

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

Examples

response_headers

Allows you to set additional HTTP headers for the response.

Params

NameTypeDescription
headersStringHeaders as JSON string, default {}.

Examples

response_status

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

Params

NameTypeDescription
statusIntHTTP status, default 200

Examples

return

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

Examples

session

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

Examples

sign_in

Sign in user.

Params

NameTypeDefinition
user_idStringuser id

Examples

spam_protection

Generates html for spam protection. Supports Google reCAPTCHA strategies: recaptcha_v2, recaptcha_v3 and 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

theme_render_rc

Allows to specify search paths for theme partials via app/config.yml property "theme_render_paths" Assuming app/config.yml looks like this: theme_search_paths : - theme/{{ context.constants.MY_THEME | default: "custom" }} - theme/simple

Examples

try_rc

Allows to catch errors, especially useful with `liquid_raise_mode: true` setting in app/config.yml.

Examples

yield

Execute code wrapped inside content_for

Params

NameTypeDescription
nameStringName of content_for block.

Examples

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.