I have written a shortcode to create a bootstrap dismissable alert box. Below is my shortcode called as layouts/shortcodes/message.html
.
<div class="alert alert-{{.Get 0}} alert-dismissible fade show" role="alert">
{{.Inner}}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
This is how I am calling from my content markdown file:
{{% message warning%}}
This can cause build errors
{{% /message %}}
However, in the output HTML, below code is generated :
<!-- raw HTML omitted -->
<p>This can cause build errors</p>
<!-- raw HTML omitted -->
I don't understand what's wrong here. I have created other shortcodes (not using .Inner though, this is my first attempt) and they work fine e.g. I created a shortcode for a image grid like pinterest that accepts upto 10 image URLs and spits out HTML. Not sure why this specific .Inner shortcode fails. Please help. My Hugo version is v0.74.3/extended darwin/amd64
.
EDIT
When I use the tags {{< >}}
instead of {{% %}}
then it works. But I may put some markdown in Inner Text and hence would like to use {{% %}}
.
If I understand correctly, using {{% %}}
will first process the markdown inside the Inner Text and then will pass that to the shortcode as .Inner
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…