This works pretty fine if the number of images are fixed (6, in this case). I can use this code above in multiple pages as long as the length of the number of images is 6.
What I want to achieve is a shortcode with variable parameters. It should adjust to the number of arguments passed.
Eg I should be able to call the same shortcode with different arguments when needed.
I am new to Hugo and new to the world of web development. Please provide a solution to this.
PS: I do not understand code much, and I am trying to. But it would be of much help if you could share the predefined code, so that I may copy and paste.
Shortcodes have their own .Params variable, which is an array (a list, also called a slice in Go) of all the parameters passed into the short code.
A working example:
layouts/shortcodes/testShortcode.html:
{{- /* Test shortcode showing how to handle an unknown number of parameters /* -}}
{{- /* the .Params variable holds all the parameters passed to the shortcode */ -}}
{{- /* https://gohugo.io/templates/shortcode-templates/#params */ -}}
<p>The following params were passed into this short code:</p>
<ul>
{{ range .Params }}
<li>{{ . }}</li>
{{ end }}
</ul>
The following params were passed into this short code:
- param1
- param2
The following params were passed into this short code:
- param1
- param2
- param3
- param4
- parma5