Hugo 0.40 is The Revival of the Shortcodes. Shortcodes is one of the prime features in Hugo. Really useful, but it has had some known shortcomings. @bep has been really busy the last week to address those.
.Content for a page retrieved in a query in a shortcode is now almost always available. Note that shortcodes can include content that can include shortcodes that can include content… It is possible to bite your tail. See more below.
Shortcodes are now processed and rendered in their order of appearance.
Related to the above, we have now added a zero-based .Ordinal to the shortcode.
The first bullet above resolves some surprising behaviour when reading other pages’ content from shortcodes. Before this release, that behaviour was undefined. Note that this has never been an issue from regular templates.
It will still not be possible to get the current shortcode’s page’s rendered content. That would have impressed Einstein.
The new and well defined rules are:
.Page.Content from a shortcode will be empty. The related .Page.Truncated.Page.Summary, .Page.WordCount, .Page.ReadingTime, .Page.Plain and .Page.PlainWords will also have empty values.
For other pages (retrieved via .Page.Site.GetPage, .Site.Pages etc.) the .Content is there to use as you please as long as you don’t have infinite content recursion in your shortcode/content setup. See below.
.Page.TableOfContents is good to go (but does not support shortcodes in headlines; this is unchanged)
If you get into a situation of infinite recursion, the .Content will be empty. Run hugo -v for more information.
This release represents 19 contributions by 3 contributors to the main Hugo code base.
We have added a timeout configuration setting. This is currently only used to time out the .Content creation, to bail out of recursive recursions. Run hugo -v to see potential warnings about this. The timeout is set default to 10000 (10 seconds).