Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Listing all values of taxonomies

Solved by Hugh Barnes View solution

Started by James Olewiler 8 years ago · 2 replies · 747 views
8 years ago

I'm just trying to list all entries of a passed in taxonomy for a collection of pages. I have a collection of sermon pages and they have an author and book associated:

YAML
title: 'The Title of the Post'
taxonomy:
    category: 'sermon'
    author: 'Person A'
    book: [Matthew,Mark,Luke]

and

YAML
title: 'Another Title of a Post'
taxonomy:
    category: 'sermon'
    author: 'Person B'
    book: [Mark,Luke,John]

What I want to see is the following:

List of Authors:

  • Person A
  • Person B

List of Books

  • Matthew
  • Mark
  • Luke
  • John

How do I output this list? And where can I learn more about the properties of the taxonomy object besides examples that list tags of a given page/item? Thanks.

last edited 12/18/18 by James Olewiler
8 years ago Solution

I remember having some trouble finding this one not long ago! It's just not a very intuitive or documented method name. The Twig I used is:

TXT
taxonomy.getTaxonomyItemKeys('category')

so substitute 'category' for 'book' or whatever.

I figured this out by studying the API docs and code but it involved lots of experimenting too, since as I mentioned it's not well covered. I think there's a way to extract slices of individual vocabs from the taxonomy tree object too, from memory.

Oh outputting as a list would be a matter of looping through the resulting array BTW. Not sure if you need help at that level.

👍 1
8 years ago

This is SUPER HELPFUL, thank you!

This method produces a collection that I can now filter and sort. I also was able to do a count of the matched entries like so using findTaxonomy():

TXT
taxonomy.findTaxonomy({'book':[PASSED IN TAG VALUE]})

Thanks again!

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 51 8 hours ago
Support · by Anna, 2 days ago
2 58 10 hours ago
Support · by Justin Young, 11 hours ago
1 30 11 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 55 5 days ago