Query on SubAttributes

Is it possible to query pages based on frontmatter subAtributes?
I have a page with the following frontmatter

---
category:
  topic: true
---

and I want to query all pages for the category.topic is true

I have tried to query this like below but it doesn't work.
${query[[from index.tag "page" where category.topic]]}

I can query like this:
${query[[from index.tag "page" where category select {_.category}]]}
which gives me a table with {topic = true}, but I want to select based on topic.

Any pointers on how to do this?

1 Like

My guess is it's because you don't have a category on every page. So you need to add a "guard clause" to filter out the pages without a category before you try to access the "topic" from within the "category".
${query[[from index.tag "page" where category and category.topic]]} should work for you.

Though, depending on what values you have in that attribute, you might need to explicitly check that the topic is 'true' as opposed to just truthy (i.e. ${query[[from index.tag "page" where category and category.topic == true ]]} ) otherwise I think anything with a non-false value set will be included:

If I have these three pages with category.topic values of true, "Some String", false
${query[[from index.tag "page" where category ]]}:

${query[[from index.tag "page" where category and category.topic]]} returns:

2 Likes

Thanks, that indeed solves it.

1 Like