1

I'm having a problem getting entries related to a tag with accentuated characters. Here is what the URL looks like : fr.craft.dev/actualites/tag/Traçage%20électrique

The same page work fine with a tag without accents.

Is there anything special to do to fix this on my side ? Or is-it a problem with craft ? Here is my code :

{% set tag = craft.tags.name(tag).first() %}
{% set newsCriteria = craft.entries.section('news').relatedTo(tag).limit(5) %}

Thanks for your help.

Nicolas

4 Answers 4

2

I try to avoid using tag titles in urls. Unlike categories, tags don't have a url-friendly slug, and the tag title itself can contain all manner of punctuation. So you have to clean up the tag somehow (slugify e.g.), and later you have to try to reconstruct the tag from the slugified value, which isn't always even possible (different tag titles can slugify to the same value). What I use instead is the tag id, which is nicely unambiguous and url-friendly.

Your route to define the url would still look like:

actualites/tag/[tag] -> whatever_template

And you would retrieve the actual tag like this:

{% set tag = craft.tags.id(tag).first() %}
5

There is a general config setting for it:

'limitAutoSlugsToAscii' => true,

Limits automatically-generated slugs to ASCII characters. When there is an obvious ASCII version of a character (e.g. ñ → n), it will be used. Other characters will be removed.

1

I suspect it's something else going on in your code.

I just did a simple test on a fresh install of Craft after adding one tag called Traçage électrique to the default entry and tag field that was created:

{% set tag = craft.tags.name('Traçage électrique').first() %}

Tag Length = {{ tag|length }}<br />

{% set entries = craft.entries.section('news').relatedTo().limit(5).find() %}

Entry Length = {{ entries|length }}

And it appears to be working fine:

Tag Length = 1
Entry Length = 1
0

I did some digging in the database, following Brad advices. First, the code was ok. Here the one I used.

{% set current_tag = craft.tags.name(tag).first() %}
{% set newsCriteria = craft.entries.section('news').relatedTo(current_tag).limit(5) %}

I find out that I had multiple tags names the same in the table "craft_content". I assume that the last one was associated to the news, and the first one was the one queried by the "name(tag).first()" call. And so there was no news associated with this tag.

I deleted all the tags in the craft_content table, and re-created them in the backoffice. Now it works perfectly.

thanks for all your help

Nicolas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.