As we know, hugo is pretty annoying sometimes. I wanted to add a new shortcode on the following premise:

Front matter:

1
2
3
4
5
6
random_name: [
	"/uploads/some-non-existing-file.zip",
	"Download title",
	"SHA1: SOME_SHA1_VALUE_TO_DOUBLE_CHECK",
	"69420 bytes"
]

Code in post

{{< download random_name >}}

The Problem

The problem was that I didn’t know how to tell that I want the (.Get 0) part of the shortcode to be pulled out of the $.Page.Params variable.

The Solution

Instead of trying all possible variations of $.Page.Params.$(Get 0) with various ticks and quotes, I found this better and more elegant solution: {{ $download := index $.Page.Params (.Get 0) }}/

1
2
3
4
5
6
7
{{ $download := index $.Page.Params (.Get 0) }}
{{ with $download }}
	<a class="download-item" target="_blank" href="{{ index . 0 }}">
		<h4>{{ index . 1 }}</h4>
		<h6>{{ index . 2 }} ({{ index . 3 }})</h6>
	</a>
{{ end }}

Ez pz.