Includes are developer-owned partial templates; snippets are editor-friendly HTML objects with no URL.
Basic use case
{% 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
{% 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
{%- 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.
Dynamically Include a Template from a Variable
{%- var dynamicTemplate = "/partials/footer-main.liquid" -%}
{%- include dynamicTemplate -%}Dynamically Include Template from a Select List
{%- 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
{%- 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
{%- 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.
<p>Show Sidebar? <strong>{{ page.show_sidebar }}</strong></p>
{%- if page.show_sidebar.checked -%}
{%- include "Sidebar" -%}
{%- endif -%}{%- capture blockContent -%}
<div class="block-outer">
<h3 class="block-title">
{%- if article.default_page_url.is_valid -%}
<a href="{{article.default_page_url.value}}">{{article.title}}</a>
{%- else -%}
{{-article.title-}}
{%- endif -%}
</h3>
<div class="block-description">{{article.summary_html}}</div>
<div class="block-footer">Posted {{article.post_date}}</div>
</div>
{%- endcapture -%}
{%- include "_block_outer" content:blockContent -%}