Puzzling behavior of `delimit`

I’ve been using delimit to concatenate two strings for ages. It has never failed me.
Until now.
In my template I have:

{{ $.Scratch.Set "counter" 0 }}
{{ partial "getchildren.html" $ }}

/layouts/partials/getchildren.html

  {{ $child_key := delimit "key" (string ( $.Scratch.Get "counter" )) "_" }}
  <br> child_key is {{ $child_key }} <br> 

And the output is

child_key is 1070101_121

I was expecting

child_key is key_0

What am I missing?

See docs:
https://gohugo.io/functions/collections/delimit/

The first argument must be a collection (e.g., a slice).

{{ $child_key := delimit (slice "key" (.Scratch.Get "counter")) "_" }}

But I’m not sure why you wouldn’t just do this instead?

{{ $child_key := print "key_" (.Scratch.Get "counter") }}
1 Like

Silly me, I had completely forgotten about the slice part. I must renew my commitment to never taking my memory for granted again…
Why I use delimit? I had just stumbled on it sometime ago, saw that it works for me and that was that. It’s just a matter of taste, I guess.
Thanks again @jmooring!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.