Page-wide data? Shortcodes/Macros?

Hi all,
I’m exploring Zola and currently playing around with adapting Using BibTeX for referencing in Zola | hertig.blog for my needs.

One thing I’d like to do is to

{% set citations = load_data(path= "references.bib", format="bibtex", required=false) %}

in my page.html template as part of the header, and then reference that dictionary in my shortcodes use in my content including the ability to modify it), so that I can then render the page footer dynamically (e.g., counting how often a reference was used, greying out unused ones, etc).

Now, this … kinda works within the page.html template: the citations dictionary is visble in later code blocks (I’m extending comments_init and page_footer from the abridge theme).

But in the shortcode, the citations dict is just invisible.

Am I running into the consequences of Shortcodes are rendered before the page's Markdown is parsed so they don't have access to the page's table of contents.?

The docs say that I should use macros if I want more than that; but I also can’t use macros in my markdown, so something like {{ ref::cite(key="foo") }} is also just rendered as plain text in the output.

If so, how can I work around this? Is that possible at all?

(I did find Include `macro` in content - #5 by HugoTrentesaux but am not sure how to wrap that.)

1 Like

Replying to myself: Any way to have a global variable across shortcodes? Sorry for missing this previously.

So yeah, shortcodes are out. But it seems a fairly common request to have a mechanism for?

1 Like