/layouts/_default/_markup/render-link.html:1:11": execute of template failed: template:
_default/_markup/render-link.html:1:11: executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkCon /layouts/_default/_markup/render-link.html:1:11": execute of template failed: template: _default/_markup/render-link.html:1:11:
executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkContext
/layouts/_default/_markup/render-link.html:1:11":
execute of template failed: template: _default/_markup/render-link.html:1:11:
executing "_default/_markup/render-link.html" at <.Get>:
can't evaluate field Get in type goldmark.linkContext /layouts/_default/_markup/render-link.html:1:11":
execute of template failed: template: _default/_markup/render-link.html:1:11:
executing "_default/_markup/render-link.html" at <.Get>: can't evaluate field Get in type goldmark.linkContext
So it doesn’t appear to work, if I add the following type check to the bottom of my code I get string as the result:
Ok, I’d like to try to get everything to work in the render-link.html file first. When I remove the safeURL from my first line in the original code it still produces the same result.
I wish this were a trivial question. It is not. The behavior changed in version 0.55, and again in 0.60.
Version
Shortcode
Markdown
HTML
0.54
{{ .Inner }}
{{< foo >}}**bold**{{< /foo >}}
**bold**
0.54
{{ .Inner }}
{{% foo %}}**bold**{{% /foo %}}
<strong>bold</strong>
0.54
<p>{{ .Inner }}</p>
{{< foo >}}**bold**{{< /foo >}}
<p>**bold**</p>
0.54
<p>{{ .Inner }}</p>
{{% foo %}}**bold**{{% /foo %}}
<p><strong>bold</strong></p>
0.55
{{ .Inner }}
{{< foo >}}**bold**{{< /foo >}}
**bold**
0.55
{{ .Inner }}
{{% foo %}}**bold**{{% /foo %}}
<p><strong>bold</strong></p>
0.55
<p>{{ .Inner }}</p>
{{< foo >}}**bold**{{< /foo >}}
<p>**bold**</p>
0.55
<p>{{ .Inner }}</p>
{{% foo %}}**bold**{{% /foo %}}
<p>**bold**</p>
0.60
{{ .Inner }}
{{< foo >}}**bold**{{< /foo >}}
**bold**
0.60
{{ .Inner }}
{{% foo %}}**bold**{{% /foo %}}
<p><strong>bold</strong></p>
0.60
<p>{{ .Inner }}</p>
{{< foo >}}**bold**{{< /foo >}}
<p>**bold**</p>
0.60
<p>{{ .Inner }}</p>
{{% foo %}}**bold**{{% /foo %}}
<!-- raw HTML omitted -->
Look at the last line.
The <!-- raw HTML omitted --> comment is rendered, without warning during the build, due to the security model introduced in Hugo 0.60. In this example, to get the desired output…
Shortcode:
<p>{{ .Inner | markdownify }}</p>
And then call it with:
{{< foo >}}**bold**{{< /foo >}}
So now we’re in the habit of coding our shortcodes templates this way, and always calling them with the {{< foo >}} notation. But there’s another big difference between the two notation styles, introduced in Hugo 0.55. From the release notes:
Shortcodes using the {{% %}} as the outer-most delimiter will now be fully rendered when sent to the content renderer (e.g. Blackfriday for Markdown), meaning they can be part of the generated table of contents, footnotes, etc.
I think this change is what makes it possible to do what you originally asked about: using the output of a shortcode within a render hook.
Comments:
Prior to deployment we always grep the public directory for <!-- raw HTML omitted --> and ZgotmplZ to find problems that Hugo doesn’t warn us about during build.
The version 0.60 examples assume default settings (i.e., you have not overridden default security settings in config.toml).
If you find this confusing you are not alone. The existing documentation is insufficient, but I’m not sure anyone understands the functionality/cases well enough to rewrite it.
Thank you !! I almost went crazy many times (and i think i understand reasonably the hugo philosophy). So when @jmooring says that, it is good for my mental health
This is the best explanation so far I ever saw. You should put that at minimum in the tip/trick section too.