# .Page.RenderString expands shortcodes in inline code blocks

**URL:** https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313
**Category:** support
**Tags:** possible-bug
**Created:** [June 30, 2022, 1:14am UTC](https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313 "2022-06-30T01:14:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)
#### Post date: [June 30, 2022, 1:14am UTC](https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313/1 "2022-06-30T01:14:34Z")

</div>

This post is a placeholder until I get time to do a proper bug report with minimal test case and all, but I thought I would give a heads up and see if anyone else has run across this (yet).

Given a shortcode like:

```auto
{{- $curPage := .Page -}}
{{- $page_asset_name := .Get 0 -}}
{{- $page_asset := resources.Get $page_asset_name -}}
{{- with $page_asset -}}
    {{- $page_asset.Content | $curPage.RenderString | safeHTML -}}
{{- end -}}

```

Which is used in a content page such as (skipping the frontmatter):

```markdown
{{< page-assets "hugo-debug-tables-README.md" >}}

```

and using an mount section in `config.toml` such as:

```nohighlight
[[module.imports]]
path = "github.com/danielfdickinson/hugo-debug-tables"
ignoreConfig = true
ignoreImports = true

[[module.imports.mounts]]
source = "README.md"
target = "assets/hugo-debug-tables-README.md"

```

Any shorcodes in the README, **even those in code blocks** are rendered with the latest Hugo.

What should happen is that the behaviour should be the same as if the content of the README where directly in the content (that is as a normal content page), which is that shortcodes in code blocks (whether full for or just `inline`) are _not_ rendered.

I’d be find with just escaping the shortcodes (as I have done as a workaround) but the backlash (`\`) character appears in the output, which is not quite right.

---

<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: [June 30, 2022, 6:48am UTC](https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313/2 "2022-06-30T06:48:41Z")

</div>

`.RenderString` now support shortcodes (this is very useful) and it behaves exactly the same as for content pages (e.g. site.Home.Content). You can use shortcodes in inline code blocks. This means that if you want to tell Hugo not to render any shortcode, you need to use the comment syntax, see this related 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: ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)
#### Post date: [June 30, 2022, 8:34am UTC](https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313/3 "2022-06-30T08:34:40Z")

</div>

Doh! I missed that. Thank you bep.

Not sure why I thought it worked with regular content.

Also yes, shortcodes in `.RenderString` is very useful. Just have to fix a few things I didn’t realize were broken.

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)
#### Post date: [July 2, 2022, 8:34am UTC](https://discourse.gohugo.io/t/page-renderstring-expands-shortcodes-in-inline-code-blocks/39313/4 "2022-07-02T08:34:50Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
