With the Section Rendering API you can request the rendered HTML of single theme sections with an Ajax request. This lets you update parts of a page, for example search results or a product area, without reloading the whole page.
If you want to update sections after a cart change, use bundled section rendering instead. It returns the sections in the same response as the cart change.
Request a single section
Add the query parameter section_id to the URL of a page. The response is the rendered HTML of this one section, in the context of the requested page:
/collections/new-arrivals?section_id=product-grid
/search?q=coat&page=2§ion_id=main-search
fetch('/collections/new-arrivals?section_id=product-grid')
.then(response => response.text())
.then(html => {
document.querySelector('#shopify-section-product-grid').outerHTML = html;
});
Which query parameters (such as q or page) are evaluated depends on the requested page.
For predictive search, /search/suggest handles q and section_id separately.
Request several sections
The parameter sections accepts up to five section IDs as a comma-separated list:
/?sections=header,footer
The result maps each requested ID to its HTML. To refresh several sections after a cart change, use bundled section rendering. On other pages, request each section with its own section_id.
Error handling
- A dynamic section ID that cannot be resolved returns an empty string.
- A static section that does not exist in the theme causes a Liquid error. The error text can appear in the output.
- A Liquid error that is not handled in the section can lead to HTTP 500 with an HTML error page.
There is no guaranteed 404 status and no null value for missing sections. Check the response before you insert it into the page.
Find section IDs
You can get a section ID in two ways:
- In Liquid with section.id
- From the wrapper element of the section: the attribute
data-section-id, or theidattribute without the prefixshopify-section-
The format of the ID depends on how the section is rendered:
| Section | ID format | Example |
|---|---|---|
Static section ({% section 'social' %}) |
File name without .liquid |
social |
| Section of a JSON template | template--<design_file_id>__<section_key> |
template--1234__main |
Section of a section group ({% sections 'header-group' %}) |
sections--<design_file_id>__<section_key> |
sections--5678__announcement |
Section wrapper
VersaCommerce wraps every rendered section in a wrapper element. For compatibility with existing themes, the wrapper uses the same IDs and classes as Shopify themes:
<div id="shopify-section-social" class="shopify-section" data-section-id="social" data-section-file-name="social" data-theme-editor-section="...">
<!-- section content -->
</div>
id:shopify-section-<section-id>class: alwaysshopify-section. If the section schema defines aclass, it is added. Sections rendered in a section group also get the classshopify-section-group-<group-name>(-groupis appended to the name if it is missing).- The element is a
divby default. The section schema can define a different tag.