Pass a variable as a section name

Shopify Partner
2 0 0

I'm trying to display a section by passing the name as a variable but get the following error:


Liquid error: Error in tag 'section' - '{{showsect1}}' is not a valid section type


I'm using the following two pieces of code. This is at the top (to concatenate the product sku with "section1", eg "MySKUsection1)":

{%- assign sect1= "section1" -%}

{% capture showsect1 %}
{{ current_variant.sku }}{{ sect1 }}
{% endcapture %}


This where I want to open the section on a page:


<div class="page-width">
{% section '{{showsect1}}' %}


I've used <SPAN> to check the output and it's correct.  If I hard code and pass section manually it also works {% section 'mysectionname' %}


I'm guessing it's a problem passing showsect1 as a variable, any ideas greatly appreciated, i've been looking at this for 4 hours :(



Shopify Expert
4221 569 1041

Hi @dash99 

Sorry but you cant do this, because you are trying to add section in side other section that cant possible. We can not add section inside other section.

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: Or WhatsApp Or Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here

Unfortunately you can't pass a liquid variable to call a section, the syntax returns an error. But to answer previous comment, you could actually nest a section inside another section, even if technically they are more like next to each other.

Someone shared this trick a while ago on the forum, it can still work with an implementation such as:


{% capture content %}{% section 'product-template' %}{% endcapture %}
{% capture section1 %}{% section 'section-1' %}{% endcapture %}
{% assign section1 = section1 | replace: 'data-shopify-editor-section', 'data-shopify-editor-section-nested' | replace: 'class="shopify-section"', 'class="shopify-section-nested"' %}
{% assign content = content | replace: '<div>Copy Paste this DIV in product-template section</div>', section1 %}
{{ content }}



C'est simple comme bonjour ! Ou presque.
Need some help to customize your website? Message me anytime: