# Can i call a shortcode from a partial?

**URL:** <https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043>\
**Category:** support\
**Created:** [June 11, 2022, 7:20pm UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043 "2022-06-11T19:20:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HiroProtagonist](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@HiroProtagonist](https://discourse.gohugo.io/u/HiroProtagonist)\
**Post date:** [June 11, 2022, 7:20pm UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/1 "2022-06-11T19:20:11Z")

</div>

Hi there,

as described in title: is it possible to call a shortcode in a partial?

If i just use the normal {{\< \>}} syntax i got a parse error.

```auto
parse failed unexpected "<" in command

```

many thanks!

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [June 11, 2022, 8:38pm UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/2 "2022-06-11T20:38:39Z")

</div>

No, you can not.

But it is possible to call a partial from a shortcode.

---

<div class="post-metadata">

**Author:** ![HiroProtagonist](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@HiroProtagonist](https://discourse.gohugo.io/u/HiroProtagonist)\
**Post date:** [June 12, 2022, 7:24am UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/3 "2022-06-12T07:24:24Z")

</div>

Okay.  
Is it possibile to append the shortcode string to the end of the content befor rendering?  
I want to display a (3rd party) gallery, which users can add to the end of a post to display pictures from the images/. folder.  
To make their lifes easier it want to add the shortcode automatically, if a flag is set in netlify cms.

---

<div class="post-metadata">

**Author:** ![frjo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/frjo/32/18626_2.png) [@frjo](https://discourse.gohugo.io/u/frjo)\
**Post date:** [June 12, 2022, 9:07am UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/4 "2022-06-12T09:07:49Z")

</div>

With “flag is set in netlify cms” I assume you refer to a frontmatter parameter.

I suggest you add a if statement to your template. Check if the parameter is set and if so add the gallery.

---

<div class="post-metadata">

**Author:** ![HiroProtagonist](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@HiroProtagonist](https://discourse.gohugo.io/u/HiroProtagonist)\
**Post date:** [June 12, 2022, 2:40pm UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/5 "2022-06-12T14:40:23Z")

</div>

Exactly that was my idea. But how to append the gallery shortcode to the post-content 🙂

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [June 12, 2022, 9:38pm UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/6 "2022-06-12T21:38:55Z")

</div>

> [@HiroProtagonist](#):
>
> Is it possibile to append the shortcode string to the end of the content befor rendering?

No.

It sounds like you need to refactor your shortcode as a partial, then programmatically call the partial from the template if the flag is set.

A common construct is to:

1. Create a partial (to be called from templates)
2. Create a shortcode that wraps the partial (if you need to call it from content)

layouts/partials/hello.html

```auto
<p>Hello {{ .name }}!</p>

```

layouts/shortcodes/hello.html

```auto
{{ partial "hello.html" (dict "name" (.Get "name")) }}

```

content/post/foo.md

```auto
{{< hello name="John Doe" >}}

```

---

<div class="post-metadata">

**Author:** ![HiroProtagonist](https://avatars.discourse-cdn.com/v4/letter/h/43a26b/32.png) [@HiroProtagonist](https://discourse.gohugo.io/u/HiroProtagonist)\
**Post date:** [June 13, 2022, 6:27am UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/7 "2022-06-13T06:27:27Z")

</div>

I had that in mind too but wanted to avoid this, because it’s a 3rd party shortcode. So i cannot easily update it.

Well, i’ll think it over. It has no priority.

Thanks for your help!

---

<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:** [June 15, 2022, 6:31am UTC](https://discourse.gohugo.io/t/can-i-call-a-shortcode-from-a-partial/39043/8 "2022-06-15T06:31:17Z")

</div>

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