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?
bep
March 15, 2017, 11:26pm
2
You can do something like this in img
:
{{ 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 …
1 Like
Not a problem. I seem to recall making notes about .Parent
somewhere, so I can review, but nonetheless for safekeeping:
opened 11:28PM - 15 Mar 17 UTC
closed 04:17AM - 16 Mar 17 UTC
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!
Thanks @bep , it is exactly what I was looking for and got answer just in 5 minutes. Much appreciated!
1 Like