225k views
3 votes
Which of the following for loop would render section blocks?

A) {% for block in section.blocks %}
B) {% for block in blocks %}
C) {% for section.blocks %}
D) {% for sections in block %}

1 Answer

4 votes

Final answer:

The correct loop to render section blocks in Liquid is {% for block in section.blocks %}, as it properly iterates through each block within the specified section.

Step-by-step explanation:

The correct for loop that would render section blocks in a templating language, such as Liquid which is commonly used in Shopify themes, is:

A) {% for block in section.blocks %}

This loop iterates through each block within a given section. Option B omits referencing 'section', which is needed to access the blocks within it. Option C is improperly formatted as a loop, and option D mistakenly swaps 'sections' and 'block', implying multiple sections inside a single block, which doesn't make sense in this context.

User Rosie
by
8.3k points