How can you get shortcodes (or partials) to expand shortcodes within them?
I want to build a shortcode (or partial) for a Disclaimer – to be cited in all posts. The disclaimer uses the admonition shortcode offered in theme uBlogger.
The final partial to display is:
{{< admonition type=warning >}}**Disclaimer**: All information on this page is my opinon and for information purposes only [snip].{{< /admonition >}}
As soon as I excise that into an own partial (or shortcode), hugo fails to run, with error:
Nesting a shortcode within a shortcode can be tricky—it depends on what each one is doing. You will need to provide code for both if you have further questions.
The table you showed at the beginning pushed me to show code for shortcode and shortcode, as partials → shortcode showed “x”.
It’s a painful limitation if shortcodes can be used neither within shortcodes nor partials. I have other cases where I’d like to recycle graphs between blog posts.
Each graph is drown using echarts, for which my theme has a echarts shortcode available. That would basically require to repeat the charts in every post, and multiply edits whenever a change must be done.
Any workaround you could think of for that, which I can further look into?
Thanks.
@iaeiou That gets you to rebuild the raw HTML for infoblocks in the partial, if I understand you right. I’d like to avoid that if possible.
To avoid any unnecessary ping-pong, here’s the process I use:
I create file layouts/partials/graph_cpi.html
I fill the file with the graph code. This code contains the {{< echarts >}} shortcode provided by my theme (as I linked in my previous answer).
I save the file. At this point already, hugo fails with Process: loading templates "[snip]: parse failed: template: partials/graph_cpi.html:1: unexpected "<" in command
At this point, I would proceed to create a shortcode that wraps the partial – but given the error, I can no longer proceed.
Now, here’s the (minimized) code of that partial:
{{< echarts >}}
{
"backgroundColor": "transparent",
"title": {
"text": "Inflation in Switzerland",
"subtext": "Consumer Price Index [CHF], 1928 to 2018. Source: Swiss Federal Statistical Office."
}
}
{{< /echarts >}}
What did I misunderstand of your proposal?
Using the echarts shortcode within the template is useful to avoid building myself the logic to load-once the respective JS dependency and graph loading code.