How to access layout data in page/post?

I have a custom layout where I assign data like this:

mylayout.html

{% assign data = "my data" %}

I’d like to use this data in the page that uses the layout:
mypage.md

---
layout: my layout
---
data: {{ data }}

When I do this, I get empty content. I’m assuming the page doesn’t know about the data variable from the layout.

not sure I have seen that type of thing with a layout - but I think you can do it with an include. Have you tried that?

1 Like

Interesting thought. That does work with an include. Thanks!