Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Custom classes in archives plugin

Solved by Pedro M View solution

Started by Pedro M 5 years ago · 1 replies · 562 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 jeremycherfas, 1 week ago
5 195 2 hours ago
General · by lynbor, 6 days ago
2 129 3 days ago
General · by Old Man Umby, 1 week ago
1 103 1 week ago
General · by Sebastian, 2 weeks ago
1 128 2 weeks ago
General · by Andy Miller, 3 weeks ago
0 251 3 weeks ago