Hugo: How to generate a random ID or use parameter in shortcode
In Hugo, you can generate a random ID string like this:
{{ $seed := now.UnixNano }}
{{ $randomId := printf "%.10s" (sha256 $seed) }}
You can use the random ID directly, or use a shortcode parameter to override it:
{{< my_shortcode id="my-id" >}}
{{/* $seed := now.Unix */}}
{{/* $randomId := printf "%.10s" (sha256 $seed) */}}
{{/* $id := .Get "id" | default $randomId */}}
<!-- Usage example -->
<div id="{{ $id }}">Hello, world!</div>