Doubt about using "with"

Hello,
I was trying to join tags of my posts using delimit like delimit .Params.tags ", " but it was crashing with the error:

error calling delimit: can’t iterate over <nil>

After going crazy I found here an answer where, to get this this work, they said to write it like this:

{{ with .Params.tags }}{{ delimit . ", "}}{{ end }}

And… it just works! Now my doubt and question is: why it wasn’t working with just delimit .Params.tags but it does using with? FYI my tags are defined like this:

---
title: Something here
headline: Brief descrition
date: "2020-09-25T15:22:06+02:00"
draft: false
toc: true
tags:
  - tag1
  - tag2
---

Cuz probably you had pages without tags, so the .Params.tags was a <nil>. The with checks if the .Params.tags is empty or not, before proceeding, avoiding such error.

1 Like

Because you have some (or one) pages without tags.

1 Like

Right, I forgot about draft posts without tags, omfg. Thank you both!

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