Shortcode to add tags to a page dynamically

How to add page tags dynamically during site generation? More precisely, I know I can add tags to any page and how taxonomies work, i.e. can generate list of pages with the term, etc.

But case in point, I would like to have a bibliography-like feature across the entire (sections of a) site. They should be implemented by a shortcode, which best looks up the “term” in its own taxonomy for generating proper link (onto the page), but also holds other information. At the same time, I would like this page to become associated with the bibliography item, i.e. tag it.

Is it possible - during the site generation - to add tags (or custom taxonomy terms) to a page from a shortcode?

Notably, I am aware there is .Page.Data.Terms object I can access from a partial that a shortcode calls, but I do not think it is going to be useful in the sense above. I also know of the .Store (.Scratch) where I can set anything, but that then won’t make use of the taxonomies, so a regular template cannot e.g. list all pages with such “dynamically” added terms.

Basically I wonder how to best go about the problem described above as such, but taxonomy terms sounded like a good way to implement bibliography site-wide. Thanks for any ideas.

No, it is not.

1 Like

Thanks for pointing me in the right direction. I guess I will then use the scratchpad and create “fake taxonomy” that will be able to list all pages that used a particular shortcode call.

The second part I wonder then is whether the templates will be used in the correct order, i.e. if there’s a way to ensure whatever page I generate reading from such scratchpad is only created after every page has written there.

EDIT Alright, I suspect I found my answer in a related post I had overlooked before.

Hugo renders templates in parallel and caches results.

So on that note, I must be better off e.g. pre-processing the content files instead, i.e. have another tool swipe through it, look at the shortcodes and add tags to the front matter.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.