# Shortcode and nested shortcodes with variables

**URL:** <https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874>\
**Category:** support\
**Created:** [March 8, 2016, 7:00pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874 "2016-03-08T19:00:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![svrist](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/svrist/32/1338_2.png) [@svrist](https://discourse.gohugo.io/u/svrist)\
**Post date:** [March 8, 2016, 7:00pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874/1 "2016-03-08T19:00:57Z")

</div>

I’m considering how to add a shortcode that wraps a set of shortcode invocations like:

```auto
{{< overall prefix="myprefix" >}}
  {{% myinner url="/url1/img1.png" %}}
  {{% myinner url="/url2/img2.png" %}}
{{< /overall >}}

```

And I’m wondering If i can “pass” the `prefix` along to each of the shortcodes in `.Inner`.

I’ve tried (in shortcode/overall.html)

```auto
$.Scratch.Add "prefix" (.Get "prefix")

```

and then in myinner.html

```auto
$.Scratch.Get "prefix"

```

but it’s empty then.  
Is it possible to do?

The idea is to have a prefix in the wrapping function and reuse it for all the inner shortcodes instead of explicitly adding them it as params.

---

<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 8, 2016, 7:19pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874/2 "2016-03-08T19:19:22Z")

</div>

> [@svrist](#):
>
> Is it possible to do?

No. The shortcodes are rendered from the inside then out. Doing it the other way is hard to wrap my brain around … Passing parameters from outer to inner should be possible to implement, but isn’t currently.

---

<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 8, 2016, 7:51pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874/3 "2016-03-08T19:51:07Z")

</div>

> <https://github.com/gohugoio/hugo/issues/1936>

---

<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 8, 2016, 7:58pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874/4 "2016-03-08T19:58:56Z")

</div>

> <https://github.com/gohugoio/hugo/pull/1937>

The above should fix this. It is work in progress (missing tests and doc), but is simple enough.

```auto
{{< outer p1="p-val" >}}
{{< inner >}}
{{< /outer }}

```

And in inner:

```auto
Parent: {{ .Parent.Get "p1" }}

```

Would this solve your use case, @svrist ?

---

<div class="post-metadata">

**Author:** ![svrist](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/svrist/32/1338_2.png) [@svrist](https://discourse.gohugo.io/u/svrist)\
**Post date:** [March 8, 2016, 8:42pm UTC](https://discourse.gohugo.io/t/shortcode-and-nested-shortcodes-with-variables/2874/5 "2016-03-08T20:42:31Z")

</div>

> [@bep](#):
>
> ```auto
> Parent: {{ .Parent.Get "p1" }}
> 
> ```
> 
> Would this solve your use case, @svrist ?

Exactly.  
I got it working by this crude hack:

```auto
<!-- in outer.html -->
  {{ replace .Inner "PREFIX" (.Get "prefix") | safeHTML }}

```

and

```auto
<!-- inner.html -->
<img src="PREFIX/{{ .Get "file" }}" />

```
