Display and style a list of taxonomy values

Greetings, fellow gravers,

Warning: noob question
I’m learning Grav from a design background, and I’m frankly amazed at what I’ve been able to do just by just testing and trying for a couple of days.

I’m using a bit of twig on a modular page to display taxonomy values from several modules:

{% set taxlist = page.taxonomy %}        
{% for tax,value in taxlist|sort %}
    {% if value is not empty %}
        {% for v in value %}
            {{ v|replace('-', ' ') }}
            <br>{% if not loop.last %},{% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}

The modular page is a list of projects. So for each module you have the title of the project, and then several bits of informations (clients and so on). The <br> is so you return to the next line after each value, like so:

Nice Project
Shop design
Corporate, Inc.

It’s just what I want, until there are 2 values for a field, such as:

Nice Project
Shop Design,
Interior Design
Corporate Inc.

I’d prefer values from the same category to be displayed on one line:

Nice Project
Shop Design, Interior Design
Corporate Inc.

Would there be a way to specify this? Such as, if values are from the same category, insert a comma and next value is displayed on the same line; if they aren’t, insert a <br> (or a <li> item, or anything);

Alternatively, would there be a way to independently select values for fields ‘Project Type’ and ‘Client’, for example?

And which method would you find better/more efficient?



values from the same category

How will any code be able to tell if values are from the same category? It seems important to know:

  • which taxonomies you have defined
  • how these are assigned to pages

Alternatively, would there be a way to independently select values for fields ‘Project Type’ and ‘Client’, for example?

I’m afraid I do not understand the question…

Thank you for reading, and sorry for the lack of clarity. I may have confused different notions here.

So my project is a portfolio (or a collection of projects), displayed on one modular page. Rather than filling up the page content with the details for each project, I used the taxonomy functionalities of Grav:

  • I created a list of taxonomy types (what I meant by ‘category’) in my site.yaml: namely, ‘Client’ and ‘Project type’
  • I then filled up the Taxonomy text areas in each module’s admin with appropriate values, different from project to project (like ‘Client: Corporate Inc.’).

The bit of code I have displays all of these values (from what I understand, any value from all taxonomy types) for each module of the page.

So the question was: would it be possible, instead of displaying all values for all taxonomy types, to display:

  • say, first, value(s) for ‘Client’
  • then (say, in another section) value(s) for ‘Project type’

My idea being that it would maybe help with the problem of styling this list of values (adding commas, spaces and line breaks where they should be).

I hope this is a better explanation!



I hope this is a better explanation!

Uhm… sorry… :thinking:

  • Why are you using taxonomies? I see no mentioning of using collections of pages with certain taxonomy values.

I suggest you take a look at two skeletons: One-Page Site and Blog Site. You can download these from Skeletons | Grav CMS

One-Page Site shows an example of a grid with images and text.
Blog Site shows an example of a typical use of Taxonomies.


Cheers, @pamtbaau! I’ll look into these.

Sorry I couldn’t make myself clearer. I’m probably mixing up different notions here.

Yep, sounds a little hacky what you are attempting. I think you are looking for a hierarchy, which Grav’s taxonomy does not offer (taxonomies normally have hierarchy actually, Grav’s is just a basic vocabulary),

You may be confused about modular pages too. I can’t quite tell because your aim and proposed design is not that clear.

Sorry, this seems like an unconstructive comment. I just caution against expecting too much from taxonomies. They are essentially separated list of tags (with some great tools too!).

1 Like

Thanks, @hughbris. It sounds there is some conceptual aspect of taxonomies I don’t really get! I’ll have to study a bit.
In the meantime looking into the skeletons @pamtbaau brought up seems like a good start to solve my problem.
Cheers, both of you