This is the function that outputs the author name(s) in the partial summary.html
{{- range .Params.authors }}
{{- with $.Site.GetPage “taxonomyTerm” (printf “authors/%s” (urlize .)) }}
By {{ .Params.authors }}
{{ end }}
with one author, it outputs
By Author One
and with two authors, it outputs
By Author One By Author Two
With two authors, how do get the output to be grammatically correct? Like this:
By Author One and Author Two
If needed, the config.toml contains:
[taxonomies]
author = "authors"
and an example-post.md front matter:
---
authors: ["Author One","Author Two"]
---
Looking at your code i guess this is what you want: (not tested yet)
{{- $theAuthors := slice -}}
{{- range $author := .Params.authors }}
{{- with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize $author)) }}
{{ $authorLink := printf `<a href=%q>%s</a>` .Permalink $author }}
{{ $theAuthors = $theAuthors | append $authorLink }}
{{- end -}}
{{ end }}
{{ if eq (len $theAuthors) 2 }}
{{ delimit $theAuthors "and" | safeHTML }}
{{ else }}
{{ delimit $theAuthors ", " "and" | safeHTML }}
{{ end }}
Thanks, that looks promising; but I get the error function "Params" not defined
on the line {{- range $author := Params.authors }}
whoops i missed the dot, should be .Params.authors
Ah, I should have seen the missing . myself. Thanks, it works great 
system
Closed
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.