# Escape shortcodes while using RenderString

**URL:** <https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331>\
**Category:** support\
**Created:** [July 1, 2022, 9:01am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331 "2022-07-01T09:01:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![xoxys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xoxys/32/17217_2.png) [@xoxys](https://discourse.gohugo.io/u/xoxys)\
**Post date:** [July 1, 2022, 9:01am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/1 "2022-07-01T09:01:38Z")

</div>

Hi,

In the past it was possible to escape shortcode syntax e.g. in a code block like this:

> <https://github.com/thegeeklab/hugo-geekdoc/blob/debug-renderstring/exampleSite/content/en/shortcodes/katex.md>

This code was working without issues in Hugo \< 0.100 while using `.RenderString`. With the current version of hugo this is no longer possible and result in the following error:

```auto
hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 linux/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
Error: Error building site: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:9:1": failed to render shortcode "columns": failed to process shortcode: "hugo-geekdoc/exampleSite/themes/hugo-geekdoc/layouts/shortcodes/columns.html:4:14": execute of template failed: template: shortcodes/columns.html:4:14: executing "shortcodes/columns.html" at <$.Page.RenderString>: error calling RenderString: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:4:1": failed to extract shortcode: template for shortcode "myshortcode" not found

```

The used `columns` shortcode is pretty simple:

> <https://github.com/thegeeklab/hugo-geekdoc/blob/debug-renderstring/layouts/shortcodes/columns.html#L4>

According to my issue [Escape shortcodes while using RenderString · Issue #10058 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/issues/10058) this might be related to some kind of “double rendering” but I have no idea where double rendering should happen… Removing `$.Page.RenderString` from the shortcode will result in not rendered markdown at all. Any idea?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 1, 2022, 9:24am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/2 "2022-07-01T09:24:31Z")

</div>

> [@xoxys](#):
>
> Any idea?

- In your case `.Inner` comes from a content file in /content which has already rendered any shortcode. So the string `{{</* myshortcode */>}}` is now rendered to `{{< myshortcode >}}`
- And then, when you pass `{{< myshortcode >}}` to `RenderString` the comments are lost and Hugo will try to find the shortcode.

I don’t understand your site in detail, but I suspect you want to drop the RenderString in this case.

---

<div class="post-metadata">

**Author:** ![xoxys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xoxys/32/17217_2.png) [@xoxys](https://discourse.gohugo.io/u/xoxys)\
**Post date:** [July 1, 2022, 9:38am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/3 "2022-07-01T09:38:41Z")

</div>

Well I want to render markdown in the `{{< columns >}}` shortcodes content. Removing `RenderString` results in completely unrendered markdown:

![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/a/f/af97b9e777c9bd4cccd177d2794ce3680d358f63.png)

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 1, 2022, 9:41am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/4 "2022-07-01T09:41:07Z")

</div>

Try:

```auto
{{% columns %}}

...

{{% /columns %}}

```

The `{{%` delimiter tells Hugo that the .Inner content is markup/markdown.

---

<div class="post-metadata">

**Author:** ![xoxys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xoxys/32/17217_2.png) [@xoxys](https://discourse.gohugo.io/u/xoxys)\
**Post date:** [July 1, 2022, 9:53am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/5 "2022-07-01T09:53:20Z")

</div>

This does not render the HTML within the `range` loop properly:

```auto
 {{ range split .Inner "<--->" }}
    <div class="gdoc-columns__content gdoc-markdown--nested flex-even">
      {{ . }}
    </div>
  {{ end }}

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/9/d/9dc459971a2620937162569d67eea1f31cd09e55.png)

This shortcode is intended to split the inner content of `{{% columns %}}` shortcode on the delimiter `<--->` and put the separated content in a div to display it as columns.

---

<div class="post-metadata">

**Author:** ![xoxys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xoxys/32/17217_2.png) [@xoxys](https://discourse.gohugo.io/u/xoxys)\
**Post date:** [July 1, 2022, 9:59am UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/6 "2022-07-01T09:59:14Z")

</div>

I can work around it by using a template:

```auto
<div class="gdoc-columns flex flex-wrap flex-mobile-column">
  {{ range split .Inner "<--->" }}
    {{ template "column" . }}
  {{ end }}
</div>

<!-- templates -->
{{- define "column" }}
  <div class="gdoc-columns__content gdoc-markdown--nested flex-even">
    {{ . | safeHTML }}
  </div>
{{- end }}

```

which produces the expected result:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/2/2/2220d317f43a3d6aca3c83192aed41b036146760.png)

No idea if this is the intended way, feels more complicated as it should be.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [July 1, 2022, 6:38pm UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/7 "2022-07-01T18:38:56Z")

</div>

I don’t have a good answer for you on this one, it seems, so I have reopened the GitHub issue:

> <https://github.com/gohugoio/hugo/issues/10058>
>
> \### What version of Hugo are you using (\`hugo version\`)?
> 
> \<pre\>
> $ hugo versio…n
> hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 linux/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
> \</pre\>
> 
> \### Does this issue reproduce with the latest release?
> Yes
> 
> In the past it was possible to escape shortcode syntax e.g. in a code block like this:
> 
> !\[image\](https://user-images.githubusercontent.com/3391958/176518945-5b49a21f-c2ae-4d69-bbe7-e295ac2284a5.png)
> 
> This snipped was rendered without issues while using \`.RenderString\`. With the current version of hugo this is no lomger possible and result in the following error:
> 
> \`\`\`
> hugo v0.101.0-466fa43c16709b4483689930a4f9ac8add5c9f66 linux/amd64 BuildDate=2022-06-16T07:09:16Z VendorInfo=gohugoio
> Error: Error building site: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:9:1": failed to render shortcode "columns": failed to process shortcode: "hugo-geekdoc/exampleSite/themes/hugo-geekdoc/layouts/shortcodes/columns.html:4:14": execute of template failed: template: shortcodes/columns.html:4:14: executing "shortcodes/columns.html" at \<$.Page.RenderString\>: error calling RenderString: "hugo-geekdoc/exampleSite/content/en/shortcodes/katex.md:4:1": failed to extract shortcode: template for shortcode "myshortcode" not found
> \`\`\`
> 
> What's the right way to escape shortcode snippets while using \`RenderString\`?

---

<div class="post-metadata">

**Author:** ![xoxys](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xoxys/32/17217_2.png) [@xoxys](https://discourse.gohugo.io/u/xoxys)\
**Post date:** [July 1, 2022, 7:47pm UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/8 "2022-07-01T19:47:06Z")

</div>

Thanks for reopening the issue, I’m also not sure yet how a fix could look like.

---

<div class="post-metadata">

**Author:** ![Wolfspyre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wolfspyre/32/17271_2.png) [@Wolfspyre](https://discourse.gohugo.io/u/Wolfspyre)\
**Post date:** [September 5, 2022, 8:19pm UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/10 "2022-09-05T20:19:26Z")

</div>

I wish I’d found this discussion, rather than opening another one.

> [@.Page.RenderString throws error when rendering an escaped shortcode call](https://discourse.gohugo.io/t/page-renderstring-throws-error-when-rendering-an-escaped-shortcode-call/40292):
>
> this was originally targeted at 0.102, but it seems like it didn’t make the cut. what is current guidance on how affected users should proceed?

Mea Culpa…

---

<div class="post-metadata">

**Author:** ![Wolfspyre](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/wolfspyre/32/17271_2.png) [@Wolfspyre](https://discourse.gohugo.io/u/Wolfspyre)\
**Post date:** [September 5, 2022, 8:28pm UTC](https://discourse.gohugo.io/t/escape-shortcodes-while-using-renderstring/39331/11 "2022-09-05T20:28:08Z")

</div>

From my perspective over here in the cheap seats with relatively little understanding of the guts of things  
(IOW CAVEAT EMPTOR)

it feels to me like there needs to be a mechanism to ask renderstring to render all of a section of content exactly once… which would involve a reordering of content processing depending on the specific site / theme / use case…

this could be a terrible red herring waste of time / a horrific idea as well… just trying to help/contribute… even if only by offering terrible ideas of what not to do 🙂

hope your days are going awesomely.

W
