Shortcodes inner with variables

I have the following situation:

Shortcode links-render.

{{ range sort $.Site.Data.links "order" }}
{{ $.Inner }}
{{ end }}

Content

{{% links-render %}}<a href="{{ .url }}" target="_blank" class="btn btn-lg btn-primary btn-icon btn-round"> <i class="fa {{ .icon }}"></i></a>{{% /links-render %}}

The problem is that it does not render the $.Inner with the local variables of the range.

Does anyone know how I can do that?

Hi,

What are you trying to do in your shortcode?

I think the confusion may be around contexts, specifically around the $ and the . (the dot).

.Inner is a shortcode variable: https://gohugo.io/variables/shortcodes/

When you are inside a range, the ‘dot’ context inside changes: https://gohugo.io/templates/introduction/#the-dot

See also docs about range: https://gohugo.io/templates/introduction/#iteration

Hi @pointyfar. Thanks for your message.

I’m using $.Inner to access the .Inner in the global context. This access seems to be working properly.

My problem is that $.Inner equals to <a href="{{ .url }}" target="_blank" class="btn btn-lg btn-primary btn-icon btn-round"> <i class="fa {{ .icon }}"></i></a>.

I would like to “render” it as a regular template, so it would use the local variables of the range and compile to something like <a href="https://twitter.com/blabla/" target="_blank" class="btn btn-lg btn-primary btn-icon btn-round"> <i class="fa fa-twitter"></i></a>.

I’ve tried many different things, but nothing has worked so far.

If I do:

{{< foo >}}THIS IS INNER{{ /foo }}

The content of .Inner is THIS IS INNER.

If you somehow want {{ .url }} to mean something, that needs to be in the shortcode template (note that we also have something called inline shortcodes, which is also very cool).

Hi @bep. Thanks for your help.

If I do:

{{< foo >}}{{ .url }}{{ /foo }}

Then, the content of .Inner is {{ .url }}, right?

I would like to “render” .Inner as a Go Text template inside a range. As if it were written inside the range block.

The string “{{ .url }}” which is probably not what you want.

I’m a bit general in my comments here, because I suspect that you need to understand the concept of it all.