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

W3C Validation Space not allowed

Started by Muut Archive 9 years ago · 2 replies · 938 views
9 years ago

Hi there,

I try to optimize my website. For this reason I checked the W3C HTML Validator. But there is one error I do not get rid of:

Illegal character in path segment: space is not allowed.

This is my html code:

TXT
<a href="/tag:MacBook pro" class="p-category">

So I use tags for taxonomy and of course some Tags do have spaces in there. So my question how can I avoid this error, but still use tags with spaces?

Thanks.

Benny

9 years ago

In order to validate, the HTML would be <a href="/tag:MacBook%20pro" class="p-category">

You could try changing your tag to MacBook%20pro but I think that is going to look weird on your page. In your theme, possibly in a file named "blog_item.html.twig", look for this code:

TWIG
  {% for tag in page.taxonomy.tag %}
    <a href="{{ blog.url|rtrim('/') }}/tag{{ config.system.param_sep }},{{ tag }}">{{ tag }}</a>
  {% endfor %}
</span>

and then change the a tag to:

TWIG
<a href="{{ blog.url|rtrim('/') }}/tag{{ config.system.param_sep }},{{ tag|url_encode }}">{{ tag }}</a>

That should fix your validation issue while leaving the displayed tag as is.

http://twig.sensiolabs.org/doc/2.x/filters/url_encode.html

9 years ago

Thank for your advice Ryan. Worked great! Thanks!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1329 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4051 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1108 9 years ago