Is it possible to access page variables from outside?

I have a page, say {{ site.url }}/books.html.

I have a variable defined in that page {% assign main_1 = "History" %} I am using this variable inside an id property like so: <a id="{{ main_1 }}" href="#{{ main_1 }}"> H1_HEADING </a> to create inner page links.

I would like to gather all of these variables and put them in the sidepanel, to create a list of inner page links. An example is this page: Modeling Non-linear Least Squares — Ceres Solver (notice how the links in the sidepanel are internal links on the same page)

My question is: Is it possible to access the variable {{ main_1 }} from outside of the current page, for example from inside includes/sidepanel.html?

you can pass parameters into an include if that would work. But you would need to call the include from that page.

You can access site variables or data files from anywhere. A data file could work depending on how complex it is but might be harder to maintain.

Thank you. How can I pass the parameters into an include? And which parameters please?

you should be able to pass in the variable to the include and then use it in the include.

see the docs:

1 Like

Thanks very much. This worked exactly as I wanted.