简体   繁体   中英

How to set the right place that I want for my Shopify Section?

As a shopify beginner, I'm wondering how the sections are placed where they are through the files.For example, I'm programming a shopping website of a brand.On top of the main page,there's a header listing some product series,where I can look through every product of the series when the mouse hover on its name.And by clicking the thumbnail I enter the description page of one product.Now I have a section called "section-1" which I want to place in some space of the product page...

I have tried adding

{% section 'section-1' %}

to theme.liquid ,just under <main>...{{content_for_layout}}...</main> ,but in this way,the section will show of all pages.I only want it to show in the description page of a certain product.

So please tell me how to add my section to some place I want,thanks.

BTW,Im not an English speaker, so my description may not be so professional and clear.....sorry for that......

There are better ways to accomplish it (from the content editing perspective) but because the question is how to limit section rendering based on template and product the answer is:

{% if template.name == 'product' and product.id == 123456789 %}
  {% section 'section-1' %}
{% endif %}

If you put it anywhere inside theme.liquid (or any other place) it will show only if the condition is true.

Note product.id is not the only option. You can use more product object properties in your if statement: Product object

Other options you could try are:

  1. Using metafields and rendering them based on content availability
  2. Using a mix of dynamic sections in 2.0 theme and metafields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM