Question: now in shortcodes?


#1

Hello,

I’m currently building another site with hugo and wanted to include some events from a data file in a shortcode (because I’m using markdown I cannot use this directly, correct?) And wanting to filter based on now.

I found this post: Trying to filter data files based upon a date field

And thought this should work:

{{ range where .Site.Data.events "date" "ge" .Now }}

But it does not. I get the following error:

<.Now>: can't evaluate field Now in type *hugolib.ShortcodeWithPage

The date in the events data yams has the format:
date: 2019-05-15

What am I doing wrong?
Thanks fo your help.


#2

Instead of

.Now

Use

now

#3

thanks for the suggestion. but when I use now nothing is displayed.


#4

You need to format the current date returned from now to match the format of your data file dates. So try:

(now.Format "2006-01-02")

Also see https://gohugo.io/functions/format/#hugo-date-and-time-templating-reference


#5

thanks. more effort than I anticipated but it works :slight_smile: