Complete newbie to all things Hugo. Have an issue with “Time”. So I have Front Matter on posts (section “rides”) which includes a ride_date as well as a created date.
This code works
{{ range (.Data.Pages.ByParam "ride_date") }}
<h2><a href='{{ .Permalink }}'> {{ .Title }}</a> </h2>
<div>Ride date - {{ .Params.ride_date }}</div>
<div>Date added - {{ .Date }}</div>
<div>Start Time - {{ .Date.Hour }}:{{ .Date.Minute }}</div>
{{ end }}
Error while rendering “section” in “rides/”: template: rides/list.html:8:36: executing “rides/list.html” at <.Params.ride_date.ho…>: can’t evaluate field hour in type interface {}
I’m stumped because the ride_date is correctly formatted in front matter
title = “Breakfast in Bampton”
date = 2018-02-23T17:10:03Z
draft = false
categories = [“Group Ride”]
ride_date = 2018-03-02T17:15:00Z
and outputs as UTC as does the .Date
If this is obvious, then I’m obviously missing something pretty fundamental here and would welcome some help.
{{ range (.Data.Pages.ByParam "ride_date") }}
{{ $page := . }}
{{ with .Params.ride_date }}
<h2><a href='{{ $page.Permalink }}'> {{ $page.Title }}</a> </h2>
<div>Ride date - {{ . }}</div>
<div>Date added - {{ $page.Date }}</div>
<div>Start Time - {{ .Hour }}:{{ .Minute }}</div>
{{ end }}
{{ end }}
From here:
If the parameter is not found at all in some entries, those entries will appear together at the end of the ordering.
So using ByParam does not guarantee that it will range only through posts with the specified param. The snippet I pasted above ensures that the .Hour, etc. date-functions are called only for posts that have the ride_date in front-matter.
I tested it locally and it works… As I have just one test post with that custom date in front-matter, I got just:
Actually a syntax like below should work, but I am not sure how to make that work with date keys… hopefully someone more knowledgeable with the use of where and date parameters can chime in.
Does not work
{{ range where .Data.Pages "Params.ride_date" "ne" nil }}
<h2><a href='{{ .Permalink }}'> {{ .Title }}</a> </h2>
<div>Ride date - {{ .ride_date }}</div>
<div>Date added - {{ .Date }}</div>
<div>Start Time - {{ .ride_date.Hour }}:{{ .ride_date.Minute }}</div>
{{ end }}