# How to use backticks inside a multiline shortcode parameter

**URL:** <https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443>\
**Category:** support\
**Tags:** shortcodes\
**Created:** [July 27, 2025, 8:31am UTC](https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443 "2025-07-27T08:31:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbaovanc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bbaovanc/32/15643_2.png) [@bbaovanc](https://discourse.gohugo.io/u/bbaovanc)\
**Post date:** [July 27, 2025, 8:31am UTC](https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443/1 "2025-07-27T08:31:29Z")

</div>

I just made a figure shortcode which can embed a page resource and be called several ways (if I made the syntax awkward, advice is welcome)

```html
{{< figure src="foo.webp" caption="Awesome words" />}}

{{< figure caption="Awesome words" >}}
  {{< resource "foo.webp" >}}
{{< /figure >}}

{{< figure "Awesome words" >}}
  <!-- in case I want to make a sort of "subfigure" setup by nesting -->
  {{< resource "foo.webp" >}}
{{< /figure >}}

{{< figure src="foo.webp" />}} <!-- fallback to .Title of the resource -->

```

The captions are rendered markdown, and it works great. But sometimes I have a caption that’s long enough to span multiple lines. I also sometimes need to put markdown code blocks inside the caption. I couldn’t see if there was a way to escape backticks inside a multiline string.

```html
{{< figure src="words.webp" caption=`
  My very awesome and long caption. Use
  a \`command spelled precisely like this\`. Need
  another line because this is too long.
`/>}}

```

This is what I was hoping for, but it doesn’t work and seems to just end the string.

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [July 27, 2025, 9:50am UTC](https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443/2 "2025-07-27T09:50:19Z")

</div>

according to this : [raw string literal](https://gohugo.io/quick-reference/glossary/#raw-string-literal) there is no way to include a backtick in a raw (multiline) string.

you could do something like that:

`layouts/_shortcodes/backtick.html`

```auto
{{- $page := .Page -}}
{{ with .Get "caption" }}
   <p>
      {{ $page.RenderString (. | replaceRE `(?s)<backtick>(.*?)</backtick>` "`$1`") }}
   </p>
{{ end }}

```

Now you may call your shortcode like that:

```plaintext
{{< backtick caption="Hello **world**" >}}

{{< ml caption=`Laborum voluptate <backtick>pariatu</backtick> ex culpa magna nostrud est incididunt fugiat pariatur do dolor ipsum enim. Consequat tempor
do dolor eu. Non id id anim anim excepteur excepteur pariatur nostrud qui irure ullamco.` >}}

{{< backtick caption=`
My very awesome and long caption. Use
a <backtick>command spelled precisely like this</backtick>. Need
another line because this is too long.
` >}}

{{< backtick caption=`
That works also if the <backtick>backtick is not closed
on the same line</backtick> and with multiple instances.My very awesome and long caption. Use
a <backtick>command spelled precisely like this</backtick>. Need
another line because this is too long.
` >}}

```

which will render as:

```html
   <p>
      Hello <strong>world</strong>
   </p>
   <p>
      Laborum voluptate <code>pariatu</code> ex culpa magna nostrud est incididunt fugiat pariatur do dolor ipsum enim. Consequat tempor
do dolor eu. Non id id anim anim excepteur excepteur pariatur nostrud qui irure ullamco.
   </p>
   <p>
      My very awesome and long caption. Use
a <code>command spelled precisely like this</code>. Need
another line because this is too long.
   </p>
   <p>
      That works also if the <code>backtick is not closed on the same line</code> and with multiple instances.My very awesome and long caption. Use
a <code>command spelled precisely like this</code>. Need
another line because this is too long.
   </p>

```

---

<div class="post-metadata">

**Author:** ![bbaovanc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bbaovanc/32/15643_2.png) [@bbaovanc](https://discourse.gohugo.io/u/bbaovanc)\
**Post date:** [July 30, 2025, 4:58am UTC](https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443/3 "2025-07-30T04:58:09Z")

</div>

Thanks, that works. I ended up just doing this in my figure shortcode since `\bt` is the easiest and fastest thing to type that I could come up with:

```html
<figure>
    {{ $resource_title := "" }}
    {{ with .Get "src" }}
        {{ with $.Page.Resources.Get . }}
            {{ $resource_title = .Title }}
            {{ partial "embed-resource.html" . }}
        {{ else }}
            {{ errorf "resource %q not found" . }}
        {{ end }}
    {{ else }}
        {{ .Inner }}
    {{ end }}

    {{ with or (.Get "caption") (.Get 0) $resource_title }}
        <figcaption>{{ (replace . "\\bt" "`") | markdownify }}</figcaption>
    {{ end }}
</figure>

```

---

<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:** [August 1, 2025, 4:58am UTC](https://discourse.gohugo.io/t/how-to-use-backticks-inside-a-multiline-shortcode-parameter/55443/4 "2025-08-01T04:58:10Z")

</div>

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