v1.9.1
Using a Layout Template
Renders current template inside a layout template from the template roots.
{% layout 'footer.liquid' %} |
When the extname option is set, the above .liquid extension can be omitted and writes:
{% layout 'footer' %} |
When a partial template is rendered by layout, the code inside it can access its caller’s variables but its parent cannot access variables defined inside a included template.
Passing Variables
Variables defined in current template can be passed to a the layout template by listing them as parameters on the layout tag:
{% assign my_variable = 'apples' %} |
Blocks
The layout file can contain multiple blocks which will be populated by the child template (the caller). For example we have a default-layout.liquid file with the following contents:
Header |
And it’s called by a page.liquid file with layout tag:
{% layout "default-layout" %} |
The render result of page.liquid will be :
Header |
Block
- Multiple blocks can be defined within a layout template;
- The block name is optional when there's only one block.
- The block contents will fallback to parent's corresponding block if not provided by child template.