Since 0.100.0 many "error calling RenderString"

Before I open an issue on Github I would like to know if it’s an expected bahavior in current Hugo version.

I have a shortcode layouts/shortcodes/ghsvs/callout.html

{{- $css_class := .Get 0 | default "info" -}}

<div class="bd-callout bd-callout-{{ $css_class }}">
{{ .Inner | $.Page.RenderString }}
</div>

that I use in markdown with more or less (in this case 2) nested shortcodes like this:

{{< ghsvs/callout "success" >}}
{{< ghsvs/code >}}
{{ $img := resources.GetRemote "https://example.org/images/avatar-.de.jpg" }}
{{ $img := $img.Content | resources.FromString "assets/images/avatar-.de.jpg" }}
<img src="{{ $img.RelPermalink }}">
Pfad ist {{ $img.RelPermalink }}.
{{< /ghsvs/code >}}
{{< /ghsvs/callout >}}

That works with Hugo 0.99.1 without any issues and creates an output like:

grafik

In current 0.100.0 I get errors like:

Error: 
Error building site: "/path/content/Divers/Readme.md:140:1": 
failed to render shortcode "ghsvs/callout": 
failed to process shortcode: 
"/path/layouts/shortcodes/ghsvs/callout.html:x:13": 
execute of template failed: 
template: shortcodes/ghsvs/callout.html:x:13: 

executing "shortcodes/ghsvs/callout.html" at <$.Page.RenderString>: 

error calling RenderString: "/path/content/Divers/Readme.md:2:209": 
got closing shortcode, but none is open

I have changed my example code above because the main point is the nested shortcode

{{< ghsvs/code >}}

{{< /ghsvs/code >}}

I’ve uploaded a test repo. The error throwing code in hugo-nested/_index.md at main · GHSVS-de/hugo-nested · GitHub

So, you problems lives here:

<div class="bd-callout bd-callout-{{ $css_class }}">
{{ .Inner | $.Page.RenderString }}
</div>

In Hugo 0.100.0 we added support for shortcodes in RenderString (a long sought after feature). RenderString was never meant to be used on the .Inner content of a shortcode, and it willl certainly not work that great now, as you have experienced.

OK, bad news and I have to exchange again my content system for ducumentations.

Just to be said:
I have read all comments on GitHub yesterday concerning “support for shortcodes in RenderString” and still I don’t understand what is supported where and why and what are the benefits in which case. I just see an unsolvable, grave B\C break and that RenderString is no longer supported inside my shortcodes which was the case in the past. How shall ““creative”” users know “what was never meant” for this or that?

1 Like

I’m sorry that your site broke. But it’s very hard to predict how thousands of users will use a certain function. The documentation is geared towards how and when to use certain features, not so much when not to use a certain function, and I’m not sure that is practical. But we surely have potential for improvements in that area (and that is being worked on).

Note that I’m pretty sure it’s possible to rewrite that code that fails for you, which I suspect will take less time than porting your site to another software.

1 Like

Same problem when using markdownify

{{ .Inner | Markdownify }}

But no solution is gfound?
Also good in 99.1 but not more in 100.0
Blocking hugo on version 99 is the only possibility I see.
Awaiting solution.
Not the first time I need to rewrite some files due to hugo update

@id027102

I think the statement of bep is clear. There won’t be an universal solution. Maybe if you pay him for one :wink:

{{ .Inner | $.Page.RenderString }}

does not fail in all contexts. In my case it depends on which nested shortcode I use.

Therefore (and because my “company partners” where nagging that I again want to change the system :wink: ) I have added an additional and optional boolean parameter and my main shortcode looka now like this:

{{- /*
- Usage: `callout "type"`[false], where `type` is one of info (default), danger, or warning.
- @since Hugo 100.0 this shortcode crashes if a < ghsvs/code > is embedded.
  - therefore parameter markdownify was introduced, which must be explicitly set to false to bypass $.Page.RenderString.
*/ -}}

{{- $css_class := .Get 0 | default "info" -}}
{{- $markdownify := .Get 1 | default true -}}
<div class="bd-callout bd-callout-{{ $css_class }}">
{{- if $markdownify -}}
  {{ .Inner | $.Page.RenderString }}
{{- else -}}
  {{ .Inner }}
{{- end -}}
</div>

In cases where the rendered result looks “weird” there is now a simplified second shortcode and my “company partners” have to live with the discomfort to restructure their content (sometimes) :wink:

“”“Creativity”“” rules! (…and the result is sometimes more exhausting.)