Although I’ve been using Hugo for various projects for some time now, this is my first post here (which means the documentation is excellent!).
In one of my current projects, I’ve got a shortcode to build an audio player and I’d like to collect some information about the (possibly many) players on the page to be able to initialize them in js at the end of the page.
PAGE.Store seems like the way to do it - the doc mentions “The Store method is often used to set values within a shortcode template, a partial template called by a shortcode template, or by a render hook template.”
So I wanted to access the current page using the global page method, but the doc says “Do not use the global page function in: - shortcodes”.
I can see why caching would prevent doing so, but still I’m not sure… Is it possible to collect data from shortcodes at the page level or is it not?
If it’s possible I’d be delighted to know how - and if not, maybe the PAGE.Store doc should be rephrased a little bit to emphasize that it’s not possible?
Also, when building a list page, it seems that .Page refers to the child page directly containing the shortcode, not the parent page actually being built. Is there a way to store information in the “top” level of the list page?
git clone --single-branch -b hugo-forum-topic-57442 https://github.com/jmooring/hugo-testing hugo-forum-topic-57442
cd hugo-forum-topic-57442
hugo server
Hugo caches rendered shortcodes. If you use the global page function within a shortcode, and the page content is rendered in two or more templates, the cached shortcode may be incorrect.
(I know we are not talking about the global page function, but the caching mechanism should still be in the way with the .Page method)
So if I get it right, there’s no way to get the “currently built” page from a shortcode, but it’s possible to “proxy” the information explicitly to “calling” pages.
Sticking together all these bits of information, I think I can do what I need. Many thanks @jmooring and @irkode for your valuable help!