# Programmatically use shortcode inside another shortcode's definition file

**URL:** <https://discourse.gohugo.io/t/programmatically-use-shortcode-inside-another-shortcodes-definition-file/11580>\
**Category:** support\
**Created:** [April 16, 2018, 9:00pm UTC](https://discourse.gohugo.io/t/programmatically-use-shortcode-inside-another-shortcodes-definition-file/11580 "2018-04-16T21:00:00Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![bademux](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bademux/32/5752_2.png) [@bademux](https://discourse.gohugo.io/u/bademux)\
**Post date:** [April 16, 2018, 11:45pm UTC](https://discourse.gohugo.io/t/programmatically-use-shortcode-inside-another-shortcodes-definition-file/11580/12 "2018-04-16T23:45:39Z")

</div>

ugly solution with [copy-pasted and a bit hacked figure.html](https://github.com/gohugoio/hugo/blob/2e95ec6844bf65a25485bdc8e2638e45788f2dcf/tpl/tplimpl/template_embedded.go#L21)  
$ cat shortcodes/shortcode1.html

```
{{- $original := .Page.Resources.GetMatch (printf "%s*" (.Get "src")) -}}
{{- $resizeParam := printf "%sx%s" (.Get "width") (.Get "height") -}}
{{- $resized := $original.Resize $resizeParam -}}
{{- .Scratch.Set "src" $resized.RelPermalink -}}
{{- .Scratch.Set "link" $original.RelPermalink -}}
{{- .Scratch.Set "height" $resized.Height -}}
{{- .Scratch.Set "width" $resized.Width -}}
{{- if isset .Params "target" -}}
{{- .Scratch.Set "target" (.Get "target") -}}
{{- end -}}
{{- if isset .Params "rel" -}}
{{- .Scratch.Set "rel" (.Get "rel") -}}
{{- end -}}
{{- if isset .Params "alt" -}}
{{- .Scratch.Set "alt" (.Get "alt") -}}
{{- end -}}
{{- if isset .Params "title" -}}
{{- .Scratch.Set "title" (.Get "title") -}}
{{- end -}}
{{- if isset .Params "caption" -}}
{{- .Scratch.Set "caption" (.Scratch.Get "caption") -}}
{{- else if .Inner -}}
{{- .Scratch.Set "caption" .Inner -}}
{{- end -}}
{{- if isset .Params "class" -}}
{{- .Scratch.Set "class" (.Get "class") -}}
{{- end -}}
{{- if isset .Params "attr" -}}
{{- .Scratch.Set "attr" (.Get "attr") -}}
{{- end -}}
{{- if isset .Params "attrlink" -}}
{{- .Scratch.Set "attrlink" (.Get "attrlink") -}}
{{- end -}}

{{ template "figure-internal" .Scratch }}

{{- define "figure-internal" -}}
<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
    {{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
        <img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}{{ with .Get "height" }}height="{{.}}" {{ end }}/>
    {{ if .Get "link"}}</a>{{ end }}
    {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
    <figcaption>{{ if .Get "title" }}
        <h4>{{ .Get "title" }}</h4>{{ end }}
        {{ if or (.Get "caption") (.Get "attr")}}<p>
        {{ .Get "caption" }}
        {{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
            {{ .Get "attr" }}
        {{ if .Get "attrlink"}}</a> {{ end }}
        </p> {{ end }}
    </figcaption>
    {{ end }}
</figure>
{{- end -}}
```

---

_[View the full topic](https://discourse.gohugo.io/t/programmatically-use-shortcode-inside-another-shortcodes-definition-file/11580)._
