If included, only one inline script will be included for each uniquename. This makes it safe to add an inline script in one or more partial templates which may be included multiple times in a page.
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax.
Options
positionoptionalvalue
Where to output the script in the current page. Must be 'head', 'in_place', or 'body'. If 'head', the script will be output inside the HTML head, if 'in_place', the script will be output immediately to the the template. If 'body', the script will be output at the end of the 'body' tag.
otheroptionalvalue
Additional attributes to include on the script tag. Additional attributes must have string values
{% end_javascript %}
This method creates a new liquid context for storing and manipulating variables.
ExampleHow to use the add_javascript methodAdd linked or inline JavaScript with add_javascript; use path, attributes, or inline blocks (once, in place, with nonce).
Add linked javascript from a path
Liquid
{% add_javascript "/jQuery.js" %}
Adds the javascript file from the specified path to the page. This is the simplest way to add javascript to a page, and by default adds it in the head of the page.
Adds the third-party javascript before the </body> tag with the additional custom attributes.
Add inline javascript once to body
Liquid
{%- add_javascript inline xxkr_once = position:'body' -%}
function doSomething() {
alert('I did something!');
}
doSomething();
{%- end_javascript -%}
Adds the inline javascript to the body of the page. Because the script is named (xxkr_once), the javascript will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each script to be included should have a unique name.
Reusing the same inline script name prevents the second script from being added
Because both scripts use the same name (xxkr_once), only the first script will be added to the page and the second script will be ignored. This may sometimes be the desired behavior, but to include both scripts either remove the name or ensure that both scripts have unique names.
Add inline javascript in place
Liquid
{%- for item in (1..3) -%}
{%- id itemid = prefix:'item_' -%}
<div id="{{itemid}}">{{item}}</div>
{%- add_javascript inline = position:'in_place' -%}doSomething('{{itemid}}');
{%- end_javascript %}
{% endfor -%}
Adds the inline javascript immediately to the template, which will result in a separate script tag for each item.
Add inline javascript in the head with a nonce attribute
Adds the inline javascript to the head of the page with a nonce attribute. The nonce attribute is used to prevent cross-site scripting (XSS) attacks by ensuring that the script is only executed if the nonce is valid. The logic for determining the nonce is left to the developer.
{% add_javascript %}
Add a script asset to the current page via a <script> tag
{% add_javascript value attributes %}Parameters
valuerequiredobject
The script to add: a Javascript object, its GUID, or its path, absolute or relative to the folder of the template being rendered, as for {% javascript %}. A value that starts with http://, https:// or // is used as the address as given. A script that is not found adds nothing and raises no error.
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Attributes for the script tag and optionally the position that you want it to be placed
Options
positionoptionalvalue
Where to output the script in the current page. Must be 'head', 'in_place', or 'body'. If 'head', the script will be output inside the HTML head, if 'in_place', the script will be output immediately to the the template. If 'body', the script will be output at the end of the 'body' tag. Any scripts added to the head or body will only be added once and additional attributes will be combined from each time it is added. If it is added to both the head and body it will be includined in the head. The default is 'head'. If the page has no head element (for 'head') or no body element (for 'body'), nothing is output and no error is raised; 'in_place' is not affected.
asyncoptionalvalue
True to include the async attribute on the script tag, or false to omit it. If the same script is added multiple times with both true and false specified, the script tag will include the async attribute
deferoptionalvalue
True to include the defer attribute on the script tag, or false to omit it. If the same script is added multiple times with both true and false specified, the script tag will include the defer attribute
otheroptionalvalue
Additional attributes to include on the script tag. Additional attributes must have string values
ExampleAdd Anonymous Javascript In PlaceAdd inline anonymous JavaScript in place (e.g. for one-off scripts) with add_javascript inline.
ExampleHow to use the add_javascript methodAdd linked or inline JavaScript with add_javascript; use path, attributes, or inline blocks (once, in place, with nonce).
Add linked javascript from a path
Liquid
{% add_javascript "/jQuery.js" %}
Adds the javascript file from the specified path to the page. This is the simplest way to add javascript to a page, and by default adds it in the head of the page.
Adds the third-party javascript before the </body> tag with the additional custom attributes.
Add inline javascript once to body
Liquid
{%- add_javascript inline xxkr_once = position:'body' -%}
function doSomething() {
alert('I did something!');
}
doSomething();
{%- end_javascript -%}
Adds the inline javascript to the body of the page. Because the script is named (xxkr_once), the javascript will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each script to be included should have a unique name.
Reusing the same inline script name prevents the second script from being added
Because both scripts use the same name (xxkr_once), only the first script will be added to the page and the second script will be ignored. This may sometimes be the desired behavior, but to include both scripts either remove the name or ensure that both scripts have unique names.
Add inline javascript in place
Liquid
{%- for item in (1..3) -%}
{%- id itemid = prefix:'item_' -%}
<div id="{{itemid}}">{{item}}</div>
{%- add_javascript inline = position:'in_place' -%}doSomething('{{itemid}}');
{%- end_javascript %}
{% endfor -%}
Adds the inline javascript immediately to the template, which will result in a separate script tag for each item.
Add inline javascript in the head with a nonce attribute
Adds the inline javascript to the head of the page with a nonce attribute. The nonce attribute is used to prevent cross-site scripting (XSS) attacks by ensuring that the script is only executed if the nonce is valid. The logic for determining the nonce is left to the developer.
If included, only one style tag will be included for each uniquename. This makes it safe to add an inline stylesheet in one or more partial templates which may be included multiple times in a page.
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax.
Options
positionoptionalvalue
Where to output the style tag in the current page. May either be "head", "body", or "in_place". If "head", the style tag will be output inside the HTML head, if "body", the style tag will be output at the end of the 'body' tag. If "in_place", the style/link tag will be output immediately to the template. The default is "head", which typically results in the best browser performance.
otheroptionalvalue
Additional attributes to include on the style tag (such as "media", "id", or "disabled"). Additional attributes must have string values
{% end_stylesheet %}
This method creates a new liquid context for storing and manipulating variables.
ExampleHow to use the add_stylesheet methodAdd linked or inline stylesheets to a page with add_stylesheet; use path, third-party URL with attributes, or inline named/in-place blocks.
Add linked stylesheet from a path
Liquid
{% add_stylesheet "/bootstrap/bootstrap.scss" %}
Adds the stylesheet from the specified path to the page. This is the simplest way to add a stylesheet to a page and may be used from any template.
Add third-party stylesheet with additional custom attributes
Adds the inline stylesheet to the body of the page. Because the stylesheet is named (xxkr_once), the stylesheet will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each stylesheet to be included should have a unique name.Adds the inline stylesheet to the page. Because the stylesheet is named (xxkr_footer_frompage), the stylesheet will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each stylesheet to be included should have a unique name.
Adds the inline stylesheet immediately to the page, which will result in a separate style tag for each item. There are typically better ways to achieve the same result, but there are times when this may be the most practical solution.
{% add_stylesheet %}
Add a stylesheet asset to the head of the current page via a <link> tag
{% add_stylesheet value attributes %}Parameters
valuerequiredobject
The stylesheet to add: a Stylesheet object, its GUID, or its path, absolute or relative to the folder of the template being rendered, as for {% stylesheet %}. A value that starts with http://, https:// or // is used as the address as given. A stylesheet that is not found adds nothing and raises no error.
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Additional attributes to include on the link tag. Attributes must have string values. "link" and "rel" are not allowed as they will always be set by this method.
Options
positionoptionalvalue
Where to output the stylesheet in the current page. May either be "head", "body", or "in_place". If "head", the stylesheet will be output inside the HTML head, if "body", the stylesheet will be output at the end of the 'body' tag. If "in_place", the stylesheet will be output immediately to the template. The default is "head", which typically results in the best browser performance. If the page has no head element (for "head") or no body element (for "body"), nothing is output and no error is raised; "in_place" is not affected.
ExampleHow to use the add_stylesheet methodAdd linked or inline stylesheets to a page with add_stylesheet; use path, third-party URL with attributes, or inline named/in-place blocks.
Add linked stylesheet from a path
Liquid
{% add_stylesheet "/bootstrap/bootstrap.scss" %}
Adds the stylesheet from the specified path to the page. This is the simplest way to add a stylesheet to a page and may be used from any template.
Add third-party stylesheet with additional custom attributes
Adds the inline stylesheet to the body of the page. Because the stylesheet is named (xxkr_once), the stylesheet will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each stylesheet to be included should have a unique name.Adds the inline stylesheet to the page. Because the stylesheet is named (xxkr_footer_frompage), the stylesheet will only be added once and can be used in one or more partial templates which may be included multiple times in a page. Each stylesheet to be included should have a unique name.
Adds the inline stylesheet immediately to the page, which will result in a separate style tag for each item. There are typically better ways to achieve the same result, but there are times when this may be the most practical solution.
{% element %} (block)
Outputs a block-level HTML element with nested content and sanitized attributes.
{% element name attributes? / %}Parameters
namerequiredstring
HTML element tag name
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Attributes to include on the resulting HTML element. Each attribute must have a string value. The keys will be output as-is and the values will be HTML encoded.
{% endelement %}
This method creates a new liquid context for storing and manipulating variables.
ExampleOutput content inside a div elementOutput content inside a div (or other wrapper) using output_content_inside or similar patterns.
Liquid
{%- element 'div' id:'maincontent' class:'container wide' -%}
{%- include '/maincontent' -%}
{%- endelement -%}
{% element / %} (self-closing)
Outputs a sanitized HTML element that is self-closed.
{% element name attributes? / %}Parameters
namerequiredstring
HTML element tag name
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Attributes to include on the resulting HTML element. Each attribute must have a string value. The keys will be output as-is and the values will be HTML encoded.
ExampleOutput self-closing input elementOutput a self-closing input (or other void) element, e.g. for forms, with correct markup.
Liquid
{% element 'input' type:'text' name:'username' placeholder:'Username' required:required / %}
{% image_url %}
Resolves the URL for an image with the desired presets and other settings applied.
If included the {% image_url %} will be output directly to the template.
var, set, or assignoptionalkeyword
Optional. Specify either "var", "set" or "assign" to change which scope this {% image_url %} is stored on. "var" is the default behavior.
variableoptionalvariable
output_to_templateoptionalflag
If included the {% image_url %} will be output directly to the template.
imagerequiredobject
Image object or its name/guid
attributesoptionalcollection
Key:value pairs. May use the variable arguments syntax. Additional options for the image URL. Currently only supports presets
Options
presetoptionalvalue
One or more image presets to apply to the image. May either be preset objects or space-separated preset codes. May be included multiple times to include multiple presets
ExampleHow to use the image_url method to get URLs for images
Simple Use Case: output URL to template
Liquid
{% image_url output_to_template = entity.image %}
Output
https://domain.com/path/to/img.jpg
This example outputs the URL of the image stored in the entity.image object to the template.
This example applies the banner-size and sepia-simple presets to the image stored in the page.banner_image object and outputs the URL to the template.
With extension, presets, and dynamic preset string
Liquid
{%- var size = 'small' -%}
{%- var bordercolor = 'red' -%}
{%- var set_transparency = true -%}
{%- capture imageCode %}thumb-{{size}} border-{{bordercolor}}{% endcapture -%}
{%- capture img_arguments %}{% if set_transparency %}preset:"transparent20" {% endif %}preset:"border10"{% endcapture -%}
{%- image_url var img_path = entity.image *img_arguments preset:imageCode -%}
This example combines multiple advanced syntax options for dynamically applying presets to the image. Multiple presets may be combined in a single string with spaces in between each preset. Additionally, the image_url method accepts the variable expansion syntax which allows for even more dynamic arguments. After all of the arguments in this example are evaluated, the result will be the equivalent of {% image_url var img_path = entity.image preset:"transparent20" preset:"border10" preset:"thumb-small" preset:"border-red" %} and the final image url will be stored in the img_path variable.
{% img %}
Shortcut to output a <img> tag for an image, optionally wrapped in a link.
{% img image attributes %}Parameters
valuerequiredobject
Image object, guid, or name
attributesoptionalcollection
Key:value pairs. May use the variable arguments syntax. Additional options for the image URL, img tag, and anchor tag (if applicable)
Options
presetoptionalvalue
Zero or more image presets; may repeat or include space-separated list
linkoptionalvalue
If string, wraps image with anchor to that URL. If true and image has a URL (page), wraps to the image URL
classoptionalvalue
Class attribute for the img tag. If included multiple times all of the classes will be included, separated by spaces
link_classoptionalvalue
Class attribute for the wrapping anchor tag, if applicable. If included multiple times all of the classes will be included, separated by spaces
link_attributeoptionalvalue
Additional attributes for the wrapping anchor tag, if applicable. Each attribute must be prefixed with "link_", may only be included once, and must have a value to be included in the anchor tag
otheroptionalvalue
Additional attributes for img tag. Each additional attribute may only be included once and must have a value to be included in the img tag
ExampleOutput an img element (and optional link) with the img shortcutUse the img shortcut to output an <img> element, optionally wrapped in a link, with presets and custom attributes.
Outputs only the <img> element when link is false.
With presets and custom attributes
Liquid
{%- img "Img for Homepage" preset:"thumb250" title:"Back to Home Page" other:"some other attribute" -%}
Output
<img src="https://www.domain.com/path/to/altered/img.jpg" alt="Image Alt Text" title="Back to Home Page" width="Image Width" height="Image Height" other="some other attribute" />
Uses a preset to alter the image and sets title and other HTML attributes on the tag.
With custom link URL and link attributes
Liquid
{%- img entity.link_img link:entity.link_destination.value link_class:"external_link" link_target="_blank" preset:"preview externallink" title:"Open In New Tab" -%}
Output
<a href="https://www.domain.com/path/to/custom/destination" class="external_link" target="_blank"><img src="https://www.domain.com/path/to/altered/img.jpg" alt="Image Alt Text" title="Open In New Tab" width="Image Width" height="Image Height" /></a>
Uses a custom link URL and sets link class and target (e.g. for external links).
Key:value pairs with unique keys. May use the variable arguments syntax. The query parameters to set or unset in the resulting link. Attributes with a value of null will be ignored, and attributes with a value of false will be unset
Any query parameters from the current request that are not explicitly unset will be included in the resulting link, including "utm" parameters. Be sure to unset all parameters that you may reasonably expect to be present on the page but do not want to include in the resulting link.
ExampleHow to use the query_param_link method to build URLs that add or replace query parameters
You can use the query_param_link method to modify multiple query parameters at once. Setting a query parameter to false in the query_param_link method removes it from the URL if it is present.
This example uses reference variables to unset the query parameter stored in the oldvarname variable and set the query parameter stored in the newvarname variable to true and newvarname variables to false and true.