Error: Can't evaluate field Site in type []string

I’m getting this error for some reason while building:

Building sites … ERROR 2018/05/13 19:11:36 Error while rendering "page" in "post/": template: /home/utkarsh/Website/blog/themes/dream-plus/layouts/post/single.html:37:8: executing "main" at <partial "tags.html" ...>: error calling partial: template: theme/partials/tags.html:1:34: executing "theme/partials/tags.html" at <.Site.Taxonomies.tag...>: can't evaluate field Site in type []string

Here is my partial tags.html:

{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
<a class="ui label" href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}" title="{{ $name }}">{{ $name }}</a>
{{ end }}

Update:

I’m also getting this as well:

Building sites … ERROR 2018/05/13 19:17:30 Error while rendering "page" in "post/": template: /home/utkarsh/Website/blog/themes/dream-plus/layouts/post/single.html:21:86: executing "main" at <.Permalink>: can't evaluate field Permalink in type string

Here is my single.html:

{{ define "title" }}
{{ .Title }}
{{ end }}

{{ define "frontmenu" }}
{{ partial "nav.html" . }}
{{ end }} 
{{ define "main" }}
<div class="ui centered grid">
	<div class="sixteen wide mobile only column">	
			{{- partial "header.html" . -}}
	</div>
	<div class="sixteen wide mobile fifteen wide tablet twelve wide computer column post-list">
		<section class="ui secondary top attached black segment post-head">
			<h1 class="post-title">
				{{ .Title }}
			</h1>
			<div class="sub header">
					<div><span><i class="calendar outline icon"></i>{{ .Date.Format "Jan 2, 2006" }}</span></div>
					{{- with .Site.DisqusShortname -}}
					<div><span class="disqusComment"><i class="comment outline icon"></i><a href="{{ .Permalink }}#disqus_thread" class="disqus-comment-count" data-disqus-identifier="{{ .UniqueID }}"></a></span></div>{{- end }}
					<div><span><i class="clock outline icon"></i>{{ .ReadingTime }} min read</span></div>
					<div><span><i class="angle double up icon"></i>{{ i18n "updateAt" }} {{ dateFormat "Jan 2, 2006" .Lastmod }}</span></div>
			</div>
			<hr>
			{{- if and .Site.Params.features.enableToc .TableOfContents -}}
			<div class="toc">
				{{- .TableOfContents -}}
			</div>
			{{ end }}
			<article class="post-content twemoji">
				{{ partial "anchor.html" .Content }}
			</article>
		</section>
		<section class="ui secondary attached segment dream-tags">
			{{- with .Params.tags -}}
				{{- partial "tags.html" . -}}				
			{{ else }}
			<span>{{ i18n "noTag" }}</span>
			{{ end }}
		</section>
		{{- if .Site.Params.features.enableShareCard -}}
		<section class="ui secondary {{ if not .Site.DisqusShortname }}bottom{{ end }} attached segment share row box">
			{{- partial "share.html" . -}}
		</section>
		{{ end }}
		<section class="ui secondary attached segment copyright">
			{{ partial "copyright.html" . }}
		</section>
		{{- if .Site.DisqusShortname -}}
		<div class="ui secondary bottom attached stacked segment disqus">
			{{- partial "disqus.html" . -}}
		</div>
		{{ end }}
	</div>
</div>
{{ end }}

Why no response?

Both look like a context issue.

@pointyfar Yes, that’s my concern as well. Any tips for me, as a beginner, to avoid those. A few starter links would be helpful.

DISCLAIMER: I am no authority at golang, so I am explaining to the best of my understanding, please correct me if I am wrong.

As far as I understand, it seems that the context gets changed because you use the with function to change the context (this dot: {{ . }}).

Here is a simplified example of your second (updated) problem):

{{- with .Site.DisqusShortname -}}
<a href="{{ .Permalink }}></a>
{{- end }}

the context here is .Site.DisqusShortname, so .Permalink essentially refers to .Site.DisqusShortname.Permalink (which does not exist, hence it cannot evaluate it.

As for the first example, I am assuming that Site.Taxonomies.tags fails to evaluate because the context is already something other than the root (so you are probably in already within a {{ range ... }} or {{ with .. }}).

Hope this clears this up for future users. This article helped me understand it better: https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/

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