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

Hyphenise tags which contain spaces

Solved by pamtbaau View solution

Started by Benjamin 5 years ago · 1 replies · 661 views
5 years ago

Now I am trying to hyphenize tags which have spaces, but if I do this:

{% set filter = p.taxonomy.prestation|join(' ')|hyphenize %}{{ filter }}

it outputs hyphens even between tags as shown below:

data-filter="sols-placo-peinture-cuisine-salle-de-bain"

Is there a solution to have hyphens only for tags, as following?

data-filter="sols placo peinture cuisine salle-de-bain"

I could not find out how to apply |hyphenize to tags only.

5 years ago Solution

@brigaill, Try the following:

YAML
// default.md

taxonomy:
  tag: [a, b, hyphenate me, c]
TWIG
// Twig

{% set tags = [] %}

{# Step 1: Hyphenise each tag and add to array of tags #}
{% for tag in page.taxonomy.tag %}
    {% set hyphenisedTag = tag|hyphenize %}
    {% set tags = tags|merge([hyphenisedTag]) %}
{% endfor %}

{# Step 2: Join array of hyphenised tags #}
{% set filter = tags|join(' ') %}
<li data-filter="{{ filter }}"></li>
HTML
// Generated HTML

<li data-filter="a b hyphenate-me c"></li>

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 93 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago