Page 1 of 1

"?" character in breadcrumb navigation

Posted: Fri Sep 18, 2009 3:43 pm
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

Re: "?" character in breadcrumb navigation

Posted: Fri Sep 18, 2009 4:01 pm
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

Re: "?" character in breadcrumb navigation

Posted: Fri Sep 18, 2009 6:09 pm
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

Re: "?" character in breadcrumb navigation

Posted: Fri Sep 18, 2009 7:50 pm
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

Re: "?" character in breadcrumb navigation

Posted: Fri Sep 18, 2009 9:12 pm
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