Extract data from shortcodes inside another page

No, it is not a hack.

Good question, and I’m not sure of the answer.

Using .Scratch or .Store to pass data between pages, or even within the same page, depends on rendering order, and Hugo renders pages in parallel.

If we need a Scratch or Store value from a page that has not been rendered, we can force the page to be rendered by doing something like:

{{ $ foo := .Content}}

There are other page methods that force the content to be rendered, including .WordCount.

The .HasShortcode method may force the page to be rendered; I am not sure. Including the noop assignment certaintly doesn’t hurt.

EDIT: I just tested this using hugo server with and without the noop assignment. Keep it.

1 Like