Escaping quote marks when using delimit

Hey folks,

I’m working on my website and I’m relatively new to Hugo.

I’m implementing seo-schema in the head of my site, and I’ve hit a problem with the following code:

"keywords" : [ {{ if isset .Params "tags" }}{{ delimit .Params.tags ", " }}, {{ end }}{{ delimit .Site.Params.seo_tags ", " }} ]

The output of the above is

"keywords": [ "tag1, tag2, tag3" ]

whereas it should be

"keywords": [ "tag1", "tag2", "tag3" ]

I’ve tried using backticks in place of the quotes like this:

"keywords" : [ {{ if isset .Params "tags" }}{{ delimit .Params.tags `", "` }}, {{ end }}{{ delimit .Site.Params.seo_tags `", "` }} ]

but that renders

"keywords": [ "tag1\", \"tag2\", \"tag3" ]

which isn’t valid syntax either.

Is there any way to enclose each item of the “delimit” loop with quotation marks?

An example of .Params.tags is as follows:

---
tags:
  - tag1
  - tag2
  - tag3

Thanks in advance.

Edit: Removed my original post.

This is better done with apply

1 Like

Thanks, this set me on the right path, I’ve ended up using the following:

     {{- if isset .Params "tags" }}
       {{- .Scratch.Set "seo_tags" (apply .Params.tags "urlize" "." ) }}
       {{- .Scratch.Add "seo_tags" (apply .Site.Params.seo_tags "urlize" ".") }}
     {{- else }}
       {{- .Scratch.Set "seo_tags" (apply .Site.Params.seo_tags "urlize" ".") }}
     {{- end }}

and then in the actual SEO Schema snippet:

        "keywords" : {{ .Scratch.Get "seo_tags" }}

and this gives me the required output.

Thanks!