-
I give a variable in my layout. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Variables you define in a page, or a layout only exist in the context of that layout or page. This is done to prevent collisions between variables names. To pass a variable from a page to the layout you do the following: In your pageTo pass the variables to the page you need to define them as part of the @layout:
path: /default
foo: bar
classes:
a: b
x: y
callout: false The
In your layoutIn your layout you can now just use these variables: <?= $foo ?>
<?= $classes ?>
<?= $callout ?> You can also make define defaults in your layout. Your code could then look like: ---
@layout: /index
foo:
classes: []
callout: true
---
<?= $foo ?>
<?= $classes ?>
<?= $callout ?> Note that since 0.21 you can also define the defaults in partials: #703. AdvancedThere also is a It allows you to dynamically inspect the layout properties, add new properties and override existing ones, giving you full control. I do recommend to use the frontmatter approach as the default approach and use For more info: #540 |
Beta Was this translation helpful? Give feedback.
-
Than you ~ :) Did I do something wrong? |
Beta Was this translation helpful? Give feedback.
Than you ~ :)
I define the layout like this screenshot.
And this is the page
but the output is
Did I do something wrong?