# \[SOLVED\] Can I check if a shortcode is inside another shortcode?

**URL:** <https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811>\
**Category:** support\
**Created:** [March 15, 2017, 11:19pm UTC](https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811 "2017-03-15T23:19:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pozitron57](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pozitron57/32/2746_2.png) [@pozitron57](https://discourse.gohugo.io/u/pozitron57)\
**Post date:** [March 15, 2017, 11:19pm UTC](https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811/1 "2017-03-15T23:19:50Z")

</div>

Sometimes I find useful to place one shortcode inside another. E.g.:

```
{{< gallery >}}
  {{< img url1 >}}
  {{< img url2 >}}
{{< /gallery >}}

```

It works fine. However, I use `{{< img >}}` shortcode both inside and outside the `{{< gallery >}}` shortcode. I’d like to set some parameters of the `img` shortcode in `shortcodes/img.html` depending on whether it is inside the `gallery` shortcode or not. I looking for something like:

```
{{ if inside gallery }}
...
{{ end }}

```

Is there a way to check this?

---

<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:** [March 15, 2017, 11:26pm UTC](https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811/2 "2017-03-15T23:26:18Z")

</div>

You can do something like this in `img`:

```auto
{{ with .Parent }}
  // This will now be the gallery shortcode if inside one
{{ end }}

```

@rdwatters I remember adding this feature, but I’m pretty sure I forgot to document it …

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [March 15, 2017, 11:29pm UTC](https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811/3 "2017-03-15T23:29:44Z")

</div>

> [@bep](#):
>
> I remember adding this feature, but I’m pretty sure I forgot to document it …

Not a problem. I seem to recall making notes about `.Parent` somewhere, so I can review, but nonetheless for safekeeping:

> <https://github.com/rdwatters/hugo-docs-concept/issues/39>
>
> Per @bep's comment in forum discussion here:
> 
> https://discuss.gohugo.io/t/can-…i-check-if-a-shortcode-is-inside-another-shortcode/5811

Thanks, Bjorn!

---

<div class="post-metadata">

**Author:** ![pozitron57](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pozitron57/32/2746_2.png) [@pozitron57](https://discourse.gohugo.io/u/pozitron57)\
**Post date:** [March 15, 2017, 11:39pm UTC](https://discourse.gohugo.io/t/solved-can-i-check-if-a-shortcode-is-inside-another-shortcode/5811/4 "2017-03-15T23:39:10Z")

</div>

Thanks @bep, it is exactly what I was looking for and got answer just in 5 minutes. Much appreciated!
