Variable in nested shortcode via .Parent

do you have any examples on how to use variables from parent shortcode in a nested shortcode

i tried:


{{ $foo := 15 }}
<div>{{ .Inner }}</div>

and leaf.html

<div>{{ with .Parent }}{{ $foo }}{{ end }}</div>


<div>{{ .Parent.Get "$foo" }}</div>


<div>{{  index .Parent "$foo" }}</div>

None worked

Only option I got working was to define param as an attribute, with leaf.html

<div>{{ .Parent.Get "foo" }}</div>

{{% tree foo="15" %}}
{{% leaf %}}
{{% /tree %}}

You can get anything from the context passed to the parent, but not vars you have defined in the parent.

1 Like

Any alternative suggestion here, can I set a property in the context of the parent? Which can be read on child?

Bit of context here, on a bootstrap accordion each item references the id of the parent, Id of parent should be unique on page

Is there any way you can use .Ordinal?

1 Like

Oh, that is relevant indeed, thanx

.Parent.Ordinal is what I used, and works great

1 Like

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