I’ve got a page with two embedded blocks of HTML which I’ve extracted to Shortcodes to keep the page Markdown tidy. There are no template functions or anything fancy in either shortcode, just plain old blocks of HTML which are too complex to render directly in Markdown.
When I generate the page, only the HTML in ‘shortcode1’ is output. If I swap the order so ‘shortcode2’ comes first, only the HTML for 'shortcode2’is output. So both shortcodes are working fine individually, but when I embed them both on a page together, only the first one is included.
Any idea why that is? There’s not an unwritten rule that a page can only contain one type of shortcode, is there?
Ah. I never even spotted that, as it was only a one-line error:
ERROR: 2015/11/11 Shortcode 'shortcode1' in page 'page.md' has no .Inner, yet a closing tag was provided
Similar error if I switch the order so the other shortcode comes first:
ERROR: 2015/11/11 Shortcode 'shortcode2' in page 'page.md' has no .Inner, yet a closing tag was provided
Weird ???
Almost looks like Hugo’s complaining that I’ve not added any template tags inside the shortcode [as I said above, it’s just plain HTML]. But, if that’s the case, why does it work when I only use one of the shortcodes on the page?
To distinguish between the first and second, we could either:
Look for a end tag that may or may not be there (until EOF)
Look in the template for an .Inner usage.
The second one is much cheaper, so that is how I implemented it. And hence you get an error because you have a closing tag but no .Inner in your shortcode.
That makes sense, now you’ve explained the mechanics behind it.
I had been expecting the shortcode tags syntax to be functionally similar the the HTML tags they resemble. So had tried both {{< shortcode1 >}}{{< /shortcode1 >}} and the [undocumented?] self-closing version {{< shortcode1 />}}