Hello all!
I’m having an issue with my single.html
. I’m trying to use a with index
statement but it’s not working as expected.
single.html:
{{ define "main" }}
<article class="post h-entry">
<h1 class="post-title p-name" itemprop="name headline">
<a href="{{ .Permalink }}">{{ .Title }}</a> {{ if .Draft }}(Draft){{ end }}
</h1>
<div class="image">
<img src="{{ .Params.cover_image }}">
</div>
<div class="post-content e-content" itemprop="articleBody">
{{ .Content | safeHTML }}
</div>
<p class="meta">
Posted on <span class="postdate"><time class="dt-published">{{ .Site.Params.DateForm | default "Jan 2, 2006" | .Date.Format }}</time></span>
{{ with index .Site.Data.authors .Params.author }}
by <span class="p-author h-card"><a href="{{ .link }}">{{ .name }}</a>
<img class="u-photo" style="display: none;" src="{{ .photo }}" />
</span>
{{ end }}
</p>
</article>
{{ end }}
Problem code:
{{ with index .Site.Data.authors .Params.author }}
by <span class="p-author h-card"><a href="{{ .link }}">{{ .name }}</a>
<img class="u-photo" style="display: none;" src="{{ .photo }}" />
</span>
{{ end }}
When running this way I receive the error
execute of template failed at <index .Site.Data.authors .Params.author>: error calling index: value is nil; should be of type string render of "page" failed: value is nil; should be of type string failed to render pages: value is nil; should be of type string
If I replace .Params.author
with a string like, "phil"
then the code works as expected.
Post frontmatter:
---
title: "Xyz"
date: 2022-08-23T10:54:07-07:00
draft: false
slug: "xyz"
description: "Testing site"
author: "phil"
tags:
- go
cover_image: https://example.org/imgs/sdl2-logo.png
---
So the question is how is .Params.author
empty? I can print it to the page just before the with index
.