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

Handling Characters in URL Slugs with Twig Filters in Grav

Started by Norbert 2 years ago · 1 replies · 343 views
2 years ago

I'm currently developing a one-page website using Grav CMS and I'm facing an issue with generating URL slugs that include Polish characters. I'm using Twig's hyphenize filter to create slugs for the navigation menu, but it does not handle Polish diacritical marks correctly. For example, "O firmie ąś" becomes "o-firmie-%EF%BF%BD-%EF%BF%BD" in the URL.

Here's the Twig code snippet I'm using for the menu:

TWIG
{% for module in page.collection() if module.header.visible is not same as(false) %}
    <li class="nav-item">
        <a class="nav-link scroll" href="#{{ module.menu|hyphenize }}">{{ module.menu }}</a>
    </li>
{% endfor %}

I need a solution that can properly translate Polish characters into standard ASCII characters for URLs (ex. "O firmie ąś" => o-firmie-as). Could someone suggest a method or a custom Twig filter that would handle this properly? Any advice or examples would be greatly appreciated.

👍 1
2 years ago

IIRC each module can have a slug, which can be enetered manually. Try using that

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 weeks ago
2 308 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 310 3 weeks ago
General · by Veehem, 4 weeks ago
0 263 4 weeks ago
General · by milkboy, 4 weeks ago
0 264 4 weeks ago
General · by ian russell, 1 month ago
2 335 1 month ago