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

Custom classes in archives plugin

Solved by Pedro M View solution

Started by Pedro M 5 years ago · 1 replies · 538 views
5 years ago

Hi.
I would like to use a custom class in the archives plugin, specifically the following:
\<span class = "{{taxonomy_color}}">

And in blog.html.twig:

{% set taxonomy_color = page.header.content.taxonomy_color %}

I have the following in the blog blueprint:

YAML
header.content.taxonomy_color:
        type: select
        label: Taxonomy color
        size: small
        options:
            blue: 'Blue'
            green: 'Green'
            yellow: 'Yellow'
            orange: 'Orange'

Am I defining the variable in the correct file, or should I define it in partials / archives.html.twig ?. I have tried both and it doesn't work.
Where should I define this variable?

Thanks

5 years ago Solution

Ok. I've found the solution:

First, in blog.html.twig I have defined one variable:

{% set taxonomy_color = page.header.content.taxonomy_color %}.

In the same file, I've include the archives.html.twig with that variable:

{% include 'partials/archives.html.twig' with {'base_url':new_base_url, 'taxonomy_color': taxonomy_color} %}

Finally, in archives.html.twig or taxonomylist.html.twig I've used taxonomy_color variable in a span tag (for example):

\<span class="label label-rounded label-{{taxonomy_color}}">

That's all. It was really easy.

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 weeks ago
2 309 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 312 3 weeks ago
General · by Veehem, 4 weeks ago
0 264 4 weeks ago
General · by milkboy, 4 weeks ago
0 267 4 weeks ago
General · by ian russell, 1 month ago
2 336 1 month ago