Hello.
I’m hitting a weird case where I get error calling len: len of untyped nil
.
I have a partial in layouts/_default/partials/press/seen.html
:
{{ $len := len $.Site.Data.press.seen.seen }}
{{ range $i, $seen := $.Site.Data.press.seen.seen }}
{{ if (eq $i 0) }}
<div class="row justify-content-center">
{{ end }}
<div class="col-12 col-sm-3 my-4">
<div class="press-logo text-center">
<a href="{{ $seen.url }}" target="_blank" rel="noopener">
<img src="{{ $seen.image }}" alt="{{ $seen.name }}'s Logo" class="img-fluid d-block mx-auto lazy" width="{{ $seen.imageWidth }}" height="{{ $seen.imageHeight }}">
</a>
</div> {{"<!-- .press-logo -->" | safeHTML }}
</div> {{"<!-- .col -->" | safeHTML }}
{{ if (eq (add $i 1) $len) }}
</div> {{"<!-- .row -->" | safeHTML }}
{{ end }}
{{ end }}
I have no problem calling this specific partial from layouts/_default/index.html
with {{ partial "home/seen" . }}
which in turns calls {{ partial "press/seen" . }}
.
The problem arises when I’m trying to call press/seen
from another layout too, with this order:
-
layouts/_default/press.html
layout file:... {{ range $j, $tabs := $.Site.Data.press.tabs.tab }} {{ $.Scratch.Set "tab-name" (.name | urlize | lower) }} <div id="{{ $.Scratch.Get "tab-name" }}" role="tabpanel" class="tab-pane fade{{ if (eq $tabs.name "About") }} show active{{ end }} {{ $.Scratch.Get "tab-name" }}-tabpanel"> {{ partial (printf "press/tabs/%s" ($.Scratch.Get "tab-name")) . }} </div> {{ end }} ...
-
This works OK until I call
{{ partial "press/seen.html" . }}
in one of the partials from step 1. The files do exist though.←[?25lBuilding sites … ERROR 2018/04/12 18:00:53 Error while rendering "page" in "": template: _default/press.html:27:27: executing "_default/press.html" at <partial (printf "pre...>: error calling partial: template: partials/press/tabs/foo.html:11:19: executing "partials/press/tabs/in-the-media.html" at <partial "press/seen....>: error calling partial: template: partials/press/seen.html:1:11: executing "partials/press/seen.html" at <len .Site.Data.press...>: error calling len: len of untyped nil
The data file is there and works fine for the homepage. The exact same partial press/seen.html
also works fine there. So, I can rule out the possibility that I have a broken data file.
Trying to debug this, after I removed the call to the partial in foo.html
, I added a couple of Context: {{ . }}
calls.
In layouts/_default/press.html
I get: Context in press layout: map[name:foo]
In layouts/_default/partials/press/foo.html
I get: Context in foo partial: map[name:foo]
Not sure if this helps at all. Maybe I’m missing something someone else has hit.
This is with Hugo 0.38.2 on Windows 7 64-bit.
Thanks in advance for any help!
PS. I tried to explain this as good as I could, but it might not be be very clear. In that case please let me know what else I can provide to debug this.