"?" character in breadcrumb navigation

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

"?" character in breadcrumb navigation

Post by yellowled »

Guys,

I'm using this code

Code: Select all

<div id="breadcrumb">
            <a href="{$serendipityBaseURL}" id="bchome">{$CONST.HOMEPAGE}</a>
        {if $view == 'categories'}
            » {$CONST.CATEGORY}: {$category_info.category_name}
        {elseif $view == 'archive'}
            » {$CONST.ARCHIVES}
        {elseif $view == 'archives'}
            » <a href="{$serendipityBaseURL}{$serendipityRewritePrefix}archives">{$CONST.ARCHIVES}</a>
        {elseif $view == 'entry'}
            » {$entry.title|truncate:40:" ...":true}
        {elseif $staticpage_pagetitle}
          {foreach name="crumbs" from=$staticpage_navigation.crumbs item="crumb"}
            » <a href="{$crumb.link}">{$crumb.name|@escape}</a>
          {/foreach}
        {elseif $view == '404'}
        {else}
            » {$head_subtitle}
        {/if}
        {if $plugin_contactform_name}» {$plugin_contactform_name}{/if}
        </div><!-- /#breadcrumb -->
to create a breadcrumb navigation in a client's blog. Unfortunately, the breadcrumb nav emits a "?" character for German umlauts in entry titles, i.e. in this entry.

So it's probably about character encoding. How do I solve this?

YL
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: "?" character in breadcrumb navigation

Post by yellowled »

Crap, I forgot: The blog is set to UTF-8, client uses Xinha, and the template file is ... uhm ... well, either in iso-8859-1 or us-ascii, I think.

YL
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: "?" character in breadcrumb navigation

Post by garvinhicking »

Hi!

UTF-8 characters are 2-byte; truncate operates on the "1-byte" basis. Unfortunately in your entry, the "ü" occurs just at 40 bytes, and half of the UTF-8 "ü" is cut, resulting in an illegal char.

Try to add or remove some spacing to make truncate operate better, or maybe don't truncate? Or you might want to check if smarty has a multibyte-string aware truncate, like PHP has substr() and mb_substr()?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: "?" character in breadcrumb navigation

Post by yellowled »

garvinhicking wrote:UTF-8 characters are 2-byte; truncate operates on the "1-byte" basis. Unfortunately in your entry, the "ü" occurs just at 40 bytes, and half of the UTF-8 "ü" is cut, resulting in an illegal char.
Ah, I see.
garvinhicking wrote:Try to add or remove some spacing to make truncate operate better, or maybe don't truncate? Or you might want to check if smarty has a multibyte-string aware truncate, like PHP has substr() and mb_substr()?
I don't think either changing the spacing or not truncating are options here. This particular client uses extremely long entry titles rather frequently, also switches between German and English frequently. There's just no way to predict a good point to truncate, but not truncating at all might result in a cluttered breadcrumb navigation.

I'll see if I can find something helpful in the Smarty docs over the weekend. Thank you so much, Garvin.

YL
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: "?" character in breadcrumb navigation

Post by yellowled »

yellowled wrote:I'll see if I can find something helpful in the Smarty docs over the weekend.
It is so incredibly easy to solve if you think about it.

Code: Select all

{$entry.title|truncate:40:" ...":false}
This makes truncate respect word boundaries, i.e. it will never truncate within a word. Hence, no split UTF-8 characters :)

YL
Post Reply