Section Rendering API within the Cart Context

asmerkin
Shopify Partner
15 1 1

Hello,

 

I'm trying to use the section rendering API to get a section that is in the cart context, like /cart/?sections=notice  ... The result comes empty and not with the section content. I can't use the section ID because I want it to be dynamic and I need to call this in the checkout.liquid file to show the information there.

I've seen that for other contexts like collections or products this is possible. I wanted to know if you have a workaround to make this work for the cart too.

Thank you!

Reply 1 (1)

James_J
Shopify Partner
38 3 6

You can pass parameter to another section using a query string via fetch

 

Try to fetch the section as follows:

 

 

<script>
  async function renderSection() {
    var appendToBody = await fetch(`/?sections=your-section-name&optional-key=optional-value-to-pass`)
    .then(response => response.json()) // It returns a promise which resolves with the result of parsing the body text as JSON.
    .then(data => { 
      $('body').append( data["your-section-name-as-key"] ); // Append the contents to the body with JQuery
    });
  }
</script>

 

 

and then call this function.