HI there: I’m trying to re-build my website that was built using the Hugo Academic theme and I got this error:
ERROR 2021/05/11 13:42:03 render of "page" failed: "/Users/skiss/OneDrive - Wilfrid Laurier University/Website/themes/academic/layouts/publication/single.html:14:10": execute of template failed: template: publication/single.html:14:10: executing "main" at <(.Params.publication_types) and (ne (index .Params.publication_types 0) "0")>: can't give argument to non-function .Params.publication_types
Honestly, I don’t even know how to read this. Where should I start looking or doing to diagnose this. The website is here . Thank you.
Please post content of publication/single.html
{{- define "main" -}}
<div class="pub">
{{ partial "page_header.html" . }}
<div class="article-container">
{{ if .Params.abstract }}
<h3>{{ i18n "abstract" }}</h3>
<p class="pub-abstract">{{ .Params.abstract | markdownify }}</p>
{{ end }}
{{ if (.Params.publication_types) and (ne (index .Params.publication_types 0) "0") }}
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<div class="col-12 col-md-3 pub-row-heading">{{ i18n "publication_type" }}</div>
<div class="col-12 col-md-9">
{{ $pub_types := partial "functions/get_pub_types" $ }}
{{ range $index, $pubtype := .Params.publication_types }}
<a href="{{ (site.GetPage "section" "publication").RelPermalink }}#{{ . | urlize }}">
{{ index $pub_types (int .) }}
</a>
{{ end }}
</div>
</div>
</div>
<div class="col-md-1"></div>
</div>
<div class="d-md-none space-below"></div>
{{ end }}
{{ if .Params.publication }}
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<div class="col-12 col-md-3 pub-row-heading">{{ i18n "publication" }}</div>
<div class="col-12 col-md-9">{{ .Params.publication | markdownify }}</div>
</div>
</div>
<div class="col-md-1"></div>
</div>
<div class="d-md-none space-below"></div>
{{ end }}
<div class="space-below"></div>
<div class="article-style">{{ .Content }}</div>
{{ partial "page_footer" . }}
</div>
</div>
{{- end -}}
The if statement need to be:
{{ if and $x $y }}
not
{{ if $x and $y }}
My apologies, somehow I failed to paste the full code the first time around. However I have revised and edited the full code now.
Does your suggestion still address the problem? I am surprised because this used to work, and I cribbed this from the hugo academic template pretty closely.
Yes.
There was a bug in the Go template package that was fixed about a year ago.
1 Like
So this line:
Needs to read ??
{{ if and (.Params.publication_types) (ne (index .Params.publication_types 0) "0") }}
Still getting this error.
Error: Error building site: failed to render pages: render of "page" failed: "/Users/skiss/OneDrive - Wilfrid Laurier University/Website/themes/academic/layouts/publication/single.html:14:47": execute of template failed: template: publication/single.html:14:47: executing "main" at <index .Params.publication_types 0>: error calling index: index of untyped nil
Code from single.html as it stands.
{{- define "main" -}}
<div class="pub">
{{ partial "page_header.html" . }}
<div class="article-container">
{{ if .Params.abstract }}
<h3>{{ i18n "abstract" }}</h3>
<p class="pub-abstract">{{ .Params.abstract | markdownify }}</p>
{{ end }}
{{ if and (.Params.publication_types) (ne (index .Params.publication_types 0) "0") }}
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<div class="col-12 col-md-3 pub-row-heading">{{ i18n "publication_type" }}</div>
<div class="col-12 col-md-9">
{{ $pub_types := partial "functions/get_pub_types" $ }}
{{ range $index, $pubtype := .Params.publication_types }}
<a href="{{ (site.GetPage "section" "publication").RelPermalink }}#{{ . | urlize }}">
{{ index $pub_types (int .) }}
</a>
{{ end }}
</div>
</div>
</div>
<div class="col-md-1"></div>
</div>
<div class="d-md-none space-below"></div>
{{ end }}
{{ if .Params.publication }}
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<div class="col-12 col-md-3 pub-row-heading">{{ i18n "publication" }}</div>
<div class="col-12 col-md-9">{{ .Params.publication | markdownify }}</div>
</div>
</div>
<div class="col-md-1"></div>
</div>
<div class="d-md-none space-below"></div>
{{ end }}
<div class="space-below"></div>
<div class="article-style">{{ .Content }}</div>
{{ partial "page_footer" . }}
</div>
</div>
{{- end -}}
One or more of your pages does not set publication_types
in front matter.
Instead of this:
{{ if and (.Params.publication_types) (ne (index .Params.publication_types 0) "0") }}
...
{{ end }}
Do this:
{{ if .Params.publication_types }}
{{ if ne (index .Params.publication_types 0) "0" }}
...
{{ end }}
{{ end }}
2 Likes
sjkiss
May 11, 2021, 8:10pm
11
OK, or I can go in and be sure to set publication types, I guess!
sjkiss
May 11, 2021, 8:52pm
12
The solution above solved the problem.
1 Like
system
Closed
May 13, 2021, 8:52pm
13
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.