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.

Themes & Styling

Spaces between tags except at beginning nor end

theme

Solved by pamtbaau View solution

Started by Benjamin 5 years ago · 2 replies · 542 views
5 years ago

Hello,

I want to output my taxonomy tags in a li tag as filter attributes as shown below:

TWIG
<li data-filter="
{% for tag in p.taxonomy.tag %}
{{ tag }}
{% endfor %}
">

It outputs this, for example if two tags are defined:

<li data-filter="FaënceFaçade">

Is there a way to have spaces between tags, but not at the beginning nor the end in order to have something like this?

<li data-filter="Faënce Façade">

It might be very simple but I spent hours without finding a solution. Any clue or help would be so much appreciated.

5 years ago Solution

@brigaill, Try the following:

TWIG
{% set filter = p.taxonomy.tag|join(' ') %}
<li data-filter="{{ filter }}">
5 years ago

Thanks so much for your help @pamtbaau , you saved me a lot of time ! I try to learn twig but as I am not a developper, it's quite hard for me.

Indeed It was that simple. I guess my mistake was trying with {% for tag in p.taxonomy.tag %} ? Because I tried the join filter, but it did not work in my code.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 202 2 months ago
Themes & Styling · by Ian, 2 months ago
3 98 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 461 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 52 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 132 3 months ago