How does `content_for_layout` load content in shopify?
Asked Answered
L

1

5

I am trying to understand the shopify.

In debut theme , theme.liquid layout file i found this code {{ content_for_layout }} inside body tag.
I am sure it is loading templates and sections, but on what basis it is loading the templates or section into it.
is it written somewhere what its gonna load?
if written, please tell me the file name or explain me the rules.

Litho answered 25/10, 2018 at 7:40 Comment(0)
B
10

content_for_layout is the main tag that handles each template content.

This means that all of the templates in the template folder are handeled with this tag.

To make it simple content_for_layout just copy the content from the template file and add it on that spot, nothing more.

Since you need to have the same header and footer in the whole site (in most cases) the tag is added in your layout file in order to create dynamic pages ( with different content that you can edit ) with the same footer and header.

content_for_layout does not handles section the way you think. You may be confusing it with content_for_index which is indeed loading sections on the homepage, but content_for_layout just takes the content that your template file outputs and show it where the tag is called at.

Bergson answered 25/10, 2018 at 10:10 Comment(2)
This is very tricky to understand. So, what happens in, for example, cart page?Influence
@Nikita the same as all other pages, it gets the header and footer from the layout and the content inside the content_for_layout is the actual cart.liquid file.Bergson

© 2022 - 2024 — McMap. All rights reserved.