tbe
1
Hey all, if have some issues with a custom shortcode:
This is the shortcode in question:
<div class="d-grid gap-3">
{{- range $img := split .Inner "\n"}}
<div>{{ $img }}</div>
{{- end }}
</div>
This is the input:
{{< imglist >}}
img/laser-burns-the-word-laser.png
{{< imglist />}}
And here is the very strange result:
<div class="d-grid gap-3">
<div></div>
<div>img/laser-burns-the-word-laser.png</div>
<div><div class="d-grid gap-3"></div>
<div> <div></div></div>
<div></div></div>
</div>
As you can see, the .Inner
contains the markup from the shortcode itself.
Did i miss something here?
tbe
3
No recursion 
<div class="d-grid gap-3">
<div>img/laser-burns-the-word-laser.png</div>
</div>
Should be the result.
Two issues.
First, you are incorrectly closing the shortcode.
Change this:
{{< imglist />}}
To this:
{{< /imglist >}}
Second, you need to trim leading and trailing newlines:
<div class="d-grid gap-3">
{{- range split (trim .Inner "\n") "\n" }}
<div>{{ . }}</div>
{{- end }}
</div>
tbe
5
Thanks, that worked. Strange behavior.
Not really. By not closing the first shortcode call, you were nesting the second shortcode call (self-closing) within the first.
1 Like
system
Closed
7
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.