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 · 477 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 Jerry Hunt, 4 days ago
2 133 1 day ago
General · by pamtbaau, 1 day ago
1 93 1 day ago
General · by Andy Miller, 2 days ago
0 77 2 days ago
General · by Marcel, 12 months ago
6 387 5 days ago
General · by Duc , 6 days ago
3 72 6 days ago