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.

General

Handling Characters in URL Slugs with Twig Filters in Grav

Started by Norbert 2 years ago · 1 replies · 201 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 Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 14 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago