Scope of liquid variables - or why is my variable not set


#1

Greetings all,

To set the stage:
I have a collection document called l01.md that uses the ‘narrative’ layout. The narrative layout uses the ‘default’ layout.

The narrative layout includes a file that assigns a variable ‘page-contains-audio’ that is used later in the layout to add the audio player html. This all works as expected.

But when the default layout is processed it includes head.html which includes a js lib and some css when the page-contains-audio variable is true.

But the variable page-contains-audio is not set at this point.

I realize I may not understand how layouts are rendered - I’ve got an inside out notion of how it is done. Starting with the collection file: l01.md then to the narrative layout and then to the default layout. If this is how it works I was assuming that a variable assigned at a lower stage in the process (the narrative layout) would be available at higher stages (the default layout and what it includes).

What am I missing? What is the correct way to do this?

Thanks in advance.


#2

@mercer33, I recently added some documentation about Jekyll’s order of interpretation. You can see it here (it’s not yet merged). Does any of the documentation answer your question?

It’s hard to follow your structure/logic here to understand what exactly is happening. Can you describe more clearly the scenario? I’d like to potentially add it to the list of scenarios in the doc.

Basically, first site variables populate, and then liquid renders, markdown processes, and files get written.


#3

@tomjohnson1492, I read your document about order of interpretation. It was so helpful and really well written. Thanks for writing it.