The default output that the stylesheets will produce when it is output directly to the template - using the "output_in_list" property of each stylesheet in the items list
List containing all of the combined stylesheets from the prepended, fetched, and appended lists. If unique is true, this list will not contain any duplicates. If max_size is set, this list will not contain more than the number of stylesheets specified.
The total number of stylesheets in the items list, including prepended, fetched, and appended lists, and respecting the unique and max_size properties.
If set, this is the maximum number of items that will be returned in the items list and the maximum number of items that will be included when this stylesheets object is enumerated as a list. When not set, this value will be 0.
The maximum number of items that were allowed to be in the list of fetched stylesheets. May be 0 in some cases (such as when when there are no fetched stylesheets.
The 1-based index of the paginated results returned in the list of fetched stylesheets, which is calculated from the start and limit parameters. Useful for paginated results.
If any items were fetched from the database, total_pages will contain the number of paginated result pages in the database for the provided arguments. This may also be calculated using the total_count and limit properties.
{% stylesheet %}
{% stylesheet output_to_template? [[var, set, or assign]? variable]? output_to_template? = value %}Parameters
output_to_templateoptionalflag
If included the {% stylesheet %} will be output directly to the template.
var, set, or assignoptionalkeyword
Optional. Specify either "var", "set" or "assign" to change which scope this {% stylesheet %} is stored on. "var" is the default behavior.
variable_nameoptionalvariable
Specify a variable name in order to save this stylesheet to a variable. If not specified, it will be output to the template instead.
valuerequiredexpression
Should evaluate to an object of type stylesheet, or the name or guid of one. May use liquid filters.
If included the {% stylesheets %} will be output directly to the template.
var, set, or assignoptionalkeyword
Optional. Specify either "var", "set" or "assign" to change which scope this {% stylesheets %} is stored on. "var" is the default behavior.
variableoptionalvariable
argumentsrequiredcollection
Key:value pairs. May use the variable arguments syntax.
Options
prependoptionallist
May be a single stylesheet, a list of stylesheets, or the name or guid of one stylesheet, to be included at the beginning of the stylesheets list.
appendoptionallist
May be a single stylesheet, a list of stylesheets, or the name or guid of one stylesheet, to be included at the end of the stylesheets list.
excludeoptionallist
May be a single stylesheet, a list of stylesheets, or the name or guid of one stylesheet that should NOT be included in the fetched results. Has no effect on prepended or appended stylesheets.
exclude_prependedoptionalboolean
True to specifically exclude all prepended stylesheets from the fetched results. If "unique:true" is specified this is the default behavior, although you may also specify "exclude_prepended:false" to allow any prepended items to be fetched along with other results anyway.
exclude_appendedoptionalboolean
True to specifically exclude all appended stylesheets from the fetched results. This is false by default - even if "unique:true" is specified - so that results are returned in the proper order.
uniqueoptionalboolean
True to remove duplicates from each of the resulting lists (prepended, fetched, appended, and items), although there may be duplicates between the prepended, fetched, and appended lists. The "items" list will include objects in the order in which they appear - with prepended items first, then fetched items, then appended items.
max_sizeoptionalinteger
The maximum number of items to be included in the "items" list. If there are any prepended or appended items, this will automatically lower the "limit" to only fetch as many stylesheets as needed. Note that this may also impact both the "page" and "total_pages" values in the resulting stylesheets. In order to use pagination with a list loaded using "max_size" use "start" instead of "page" and "limit".
stylesheet_typeoptionalvalue
Only include stylesheets of the given type
compiledoptionalvalue
Only include stylesheets that either are or are not compiled
is_legacyoptionalvalue
only include stylesheets that are marked as using a legacy compiler
pathoptionalvalue
May include multiple paths. Only include stylesheets with one of the given paths (excluding child paths)
date_created_startoptionalvalue
Only include stylesheets with date_created greater than or equal to date_created_start. Remember that date_created will typically be the date that the stylesheet was first published.
date_created_endoptionalvalue
Only include stylesheets with date_created less than or equal to date_created_end. Remember that date_created will typically be the date that the stylesheet was first published.
startoptionalinteger
Set the 1-based index of the first stylesheet to fetch.
pageoptionalinteger
Used to automatically calculate the first stylesheet to fetch based on both the "limit" and the 1-based "page" value. Defaults to 1, but is ignored if "start" is set.
limitoptionalinteger
The maximum number of stylesheets to fetch. Defaults to 10. Note that if "max_size" is defined, then "limit" may be automatically lowered even if specified separately.
sort_byoptionalstring
Specify which property to sort the results by. Has no effect on prepended or appended stylesheets. Options include:
date_created: the date each stylesheet was first published. Unpublishing and republishing one resets date_created to the current date.
random: results will be returned in a random order, which prevents the page from being fast-cached. Setting cache_random:true overrides this behavior and allows the page to be fast-cached anyway.
name
title
url
browser_title
sort_directionoptionalstring
asc or desc.
cache_randomoptionalboolean
True to allow the results to be cached when sort_by is "random".
Add a stylesheet asset to the head of the current page via a <link> tag
{% add_stylesheet value attributes %}Parameters
valuerequiredobject
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.
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.
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.
{% include %}
Processes and outputs a partial template, javascript, or stylesheet. If the partial template is a compiled template, then any custom fields from the partial template will be available in the parent template as well.
{% include [template|javascript|stylesheet]? variable =? attributes? %}Parameters
typeoptionalstring
Explicit type selector: template, javascript, or stylesheet. If not specified, the object to be included will be the same as the type of the current ojbect (in a template this will default to template, etc...).
variablerequiredobject
May be the template, javascript, or stylesheet object to include, the unique identifier for the object to include, or the relative or absolte path to the template, javascript, or stylesheet
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Variables to set on the created scope before the included object is processed
This method creates a new liquid context for storing and manipulating variables.
The path is significant when including objects. Every template, javascript, and stylesheet has a path, even if that is the "root path" (/). The location of the path to be included will always be based off of the path of the current object. So including 'header' from a template at the path '/pages' will attempt to process '/pages/header' while the same include from a template at the root path - which would attempt to process '/header'. You always have the option of using an "absolute path" when including templates by beginning your included template name with '/'. Eg: {% include '/header' %} or {% include '/partials/header' %}. Absolute paths ignore the path of the current template when determining what partial to include. You can also navigate up the directory structure using '../'. So including '../partials/header' from a template at the path '/agency/pages' will attempt to process '/agency/partials/header'.
ExampleCapturing markup and passing it to an included templateCapture a block of markup with the capture tag and pass it to an included template as a variable.
ExampleCheckbox Include Partial TemplateInclude a partial template conditionally when a checkbox (or other) field is checked.
Liquid
<p>Show Sidebar? <strong>{{ page.show_sidebar }}</strong></p>
{%- if page.show_sidebar.checked -%}
{%- include "Sidebar" -%}
{%- endif -%}
ExampleInclude a template whose name is in a variableDemonstrates multple ways to dynamically include a template. Note that in all of these examples, the template fields will NOT be compiled in the page definition.
Dynamically Include a Template from a Variable
Liquid
{%- var dynamicTemplate = "/partials/footer-main.liquid" -%}
{%- include dynamicTemplate -%}
Dynamically Include Template from a Select List
Liquid
{%- if page.page_layout.is_valid -%}
<div class="sidebar-{{ page.page_layout.value }}">
{%- var includeTemplate = "/theme/sidebar/" | append:page.page_layout.value -%}
{%- include includeTemplate -%}
</div>
{%- endif -%}
Assuming that page_layout is a select field or similar, this code dynamically creates the name of the template to include based on the selected value.
Dynamically Include Multiple Templates from a TemplateList Field
Liquid
{%- if page.sidebar_sections.count > 0 -%}
{%- for section in page.sidebar_sections.selected -%}
{%- include section -%}
{%- endfor -%}
{%- endif -%}
Assuming that sidebar_sections is a templatelist field or similar, this code dynamically includes each of the selected templates.
Check if a dynamic template exists before including it
Liquid
{%- template var dynamicTemplate = "/theme/sidebar/" | append: page.sidebar_section.value | append: ".liquid" -%}
{%- if dynamicTemplate.is_valid -%}
{%- include dynamicTemplate -%}
{%- endif -%}
Assuming that sidebar_sections is a templatelist field or similar, this code dynamically includes each of the selected templates.
ExampleHow to use the {% include %} method
Basic use case
Liquid
{% include "/_header.liquid" %}
Includes the partial template from the specified path. This is the simplest way to include a partial template.
Include partial by string with attributes
Liquid
{% include "/sections/_banner.liquid" section_class:'banner-section mb-5' show_title:true show_description:false %}
Includes the partial template from the specified path. The new scope created by the include method will have the specified attributes available as variables.
Expanded example with relative and absolute paths
Liquid
{%- search searchCollection "keyword" limit:10 page:search-page -%}
{%- for result in searchCollection -%}
{%- include "./search-result.liquid" item:result -%}
{%- endfor -%}
{%- include "/shared/_pagination.liquid" collection:searchCollection style:"links" max_links:5 -%}
Includes the partial template from the specified path. The relative path is relative to the current template, and the absolute path is relative to the root of the website.
ExampleInline javascript from templateOutput inline JavaScript from template variables (e.g. for config or data) with proper escaping.
Liquid
<script>{% include javascript "/javascript/inlined/blog" %}</script>
OR
{%- javascript js = "/javascript/inlined/blog" -%}
{%- if js is_valid -%}
<script>{% include js %}</script>
{%- endif -%}
ExampleInclude sidebar template unless a query param is falseInclude a sidebar template only when a query parameter is not false, using unless.