Hi everyone.
I have a short question and i dont know how i can solve it. I want to insert a few images for every post, every image should also work as a link. I decided to create a new archtype. In the Front Matter i want to set a multidimensional array.
+++
imagegallery = [["/path/to/img1.png", “http://link.tld ”], ["/path/to/img2.png", “http://example.tld ”]]
+++
In the Partial i want to define an Img Tag with an link.
But how can i iterate through the multidimensioal array, is there way to do that?
thanks
TomEjc
March 27, 2020, 9:33am
2
Hello,
You can use function Split or transform.Unmarchal . I haven’t tested the Unmarchal function, but Split works like this - using two separators:
{{ $imagegallery := "'/path/to/img1.png','http://link.tld';'/path/to/img2.png','http://example.tld'" }}
{{ $ig_split := split $imagegallery ";" }}
<ul>
{{ range $i, $ig := $ig_split }}
<li>
{{ $i }}: {{ $ig }}
{{ $ig2_split := split $ig "," }}
<ul>
{{ range $j, $ig2 := $ig2_split}}
<li>
{{ $j }}: {{ $ig2 }}
</li>
{{ end }}
</ul>
</li>
{{ end }}
</ul>
Result:
* 0: '/path/to/img1.png','http://link.tld'
* 0: '/path/to/img1.png'
* 1: 'http://link.tld'
* 1: '/path/to/img2.png','http://example.tld'
* 0: '/path/to/img2.png'
* 1: 'http://example.tld'