Using range where with front-matter values

#1

I have this in my front page template:

            {{- range where .Pages "Params.featured" "true" -}}
            <li>
                <a href="{{ .RelPermalink }}">{{ .Title }}</a>
                <!-- <div class="summary">{{.Summary}}</div> -->
            </li>
            {{- end -}}

and I have this in some of my post front-matter blocks:

---
date: 2019-05-07T13:30:00-07:00
title: Beer Tourism
type: posts
tags:
- Travel
- Beer
images:
- /images/beer_tourism.jpg
description: Finding interesting beer while traveling
featured: true
---

but the range statement isn’t returning anything. If I switch it to something like range (first 3 .Pages) that works as expected, but I would rather be pulling up a list of posts based on this front-matter value.

Can someone explain how the where should be used, and what I’m doing wrong? :slight_smile:

Thanks!

#2

Share the site you are working on, so we can see what’s happening. :slight_smile:

#3

The code doesn’t work, so I haven’t pushed it live… because it doesn’t work :slight_smile:

It is more of a technique question, how to pull back a list of posts based on a front-matter value

#4

"true" is a string; true is a boolean.

3 Likes
#5

That was it, thanks. Works perfectly now by just dropping the quotes around “true” when doing the where clause!