Is there a way to debug (as in step through) templates? Because from reading the code I don’t see the problem.
{{ $self := . }}
{{ $related := len (.Params.related | default "") }}
{{ $cols := 3 }}
{{ $show := 3 }}
{{ $mod := mod $related $cols }}
{{ $sum := add $related $mod }}
{{ $total := cond (ge $sum $show) $sum $show }}
{{ $.Scratch.Set "tiles" (dict $self.File.Path 1) }}
<section class="more">
<ol>
{{ range .Params.related }}
{{ with $.Site.GetPage "page" . }}
{{ if not (index ($.Scratch.Get "tiles") .File.Path) }}
<li class="related">
{{ partial "article_tile.html" (dict "text" "related" "article" .) }}
{{ $.Scratch.SetInMap "tiles" .File.Path 1 }}
</li>
{{ end }}
{{ end }}
{{ end }}
{{ range $post := first 10 (where $.Site.Pages "Section" "posts") }}
{{ if le (len ($.Scratch.Get "tiles")) $show }}
{{ with $.Site.GetPage "page" $post.File.Path }}
{{ if not (index ($.Scratch.Get "tiles") .File.Path) }}
<li class="recent">
{{ partial "article_tile.html" (dict "text" "recent" "article" $post) }}
{{ $.Scratch.SetInMap "tiles" .File.Path 1 }}
</li>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</ol>
</section>
I would think $self
being .
should never be a zero object, $post
should never be zero as it’s coming from range
(unless I misunderstand the first 10
) and all other .File.Path
are wrapped in a with
. And shouldn’t a .File
always have a .Path
anyway?