Added support for using post categories in email newsletter templates.
@news π
@news does it work for existing newsletters (in case I want to change the template and re-send it myself to try?) Is it .Pages.Params.categories
?
@news I'm getting "Newsletter: Error running template, Error parsing template: template: template:53: function "in" not defined". If it's .Pages.Params.categories
, is it an array?
@news it didn't work with in
as it did for blog posts, but if I use range
I can iterate over the categories and check if the one I need is there. Thanks!
@otaviocc I'm updating the help page about this. For each blog post in .Pages
, there should be .Params.categories
now. Let me know if that matches what you're seeing.
@manton exactly, as I mentioned I used range
to access it. I noticed is that the same code from a blog post doesnβt work for newsletters. Take the following example which works for posts:
{{ if .Params.categories }}
{{ if in .Params.categories "Article" }}
π
{{ else if in .Params.categories "Video" }}
π₯
{{ else }}
πͺ΄
{{ end }}
{{ end }}
When the code above is used in newsletters, the compiler complains that the function in
(doc) is not present. The solution, in newsletters, is to use range
(doc) to iterate over all the categories for that particular post and check if the category matches the criterion.
{{ if .Params.categories }}
{{ range .Params.categories }}
{{ if eq . "Article" }}
π
{{ else if eq . "Video" }}
π₯
{{ else }}
πͺ΄
{{ end }}
{{ end }}
{{ end }}
Maybe newsletters are processed outside Hugo? And in
is implemented by Hugo and not by Go?