How can use a shortcode within {{<figure src="..." >}}?

I’d like to use

{{<figure src="{{<static "blah">}}">}}

where static is a shortcode that gives the absolute path for static content files as follows:

{{- .Scratch.Set "path" (.Get 0) -}}
{{- if hasPrefix (.Scratch.Get "path") "/" -}}
  {{- .Scratch.Set "path" (slicestr (.Scratch.Get "path") 1) -}}
{{- end -}}
{{- .Scratch.Get "path" | absLangURL -}}

I cannot get the syntax of nesting right. How can I do this? Alternatively, I also looked into whether Hugo could do something along the lines of

<!-- pseudocode -->
{{capture into path}}{{<static "blah">}}{{end capture}}
{{<figure src="path">}}

but apparently Hugo doesn’t support any concept similar to rendering to a variable.

You cannot. Instead, create your own figure shortcode, and do your URL transformation there.

1 Like

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