By Mel55113 on
I'm using a fluid theme (NewsFlash) on a site I'm developing. I'd like to be able to use special characters like non-breaking spaces in page/story titles to control how they break on narrower displays. E.g. I'd like to use non-breaking spaces in dates like "September 15, 2007" to keep the date together instead of getting a line break after September or the comma.
I've tried just about every trick I can think of including &@160;,  , \00a0, <pre></pre> tags, and using the ALT-0160 keyboard technique but it either doesn't work (ALT-0160) or shows as the escape sequence, e.g. September 15, 2007.
Anyone know how to get around this problem?
TIA,
Mel
Comments
page.tpl.php
You have to change your page.tpl.php. Search for $title and replace it by $node->title.
(the variable $title is set in phptemplate.engine to check_plain($node->title), which removes any special chars)
And node.tpl.php and ...
That was a good start, but it looks like a couple of changes are needed in node.tpl.php, and probably some other changes.
I was hoping that this would be simple but it's turning out to be more difficult than I expected and I have some higher priorities that I need to tend to.
This one's going on the back burner for a while.
Thanks,
Mel
Wonderful! Worth the time
Wonderful! Worth the time to change it in the various tpls....
However, in drupal 5, you can simply use the unicode character, and it will show correctly in tltles, book navigation, etc.
Maria
Working in some places and not others
I am using Drupal 6.3 and also need to be able to use special characters in content titles. I followed the suggestion of replacing $title with $node->title in the page.tpl.php, as well as the node.tpl.php. This works for the title of the node but does not work for name of the node when it appears in the breadcrumb or the title of the page. In both instances, the Uni is displayed.
Any ideas?
template.php
With Drupal 6 the best way to do this is to add a function phptemplate_preprocess_page into template.php and to change the $title and the $head_title. The breadcrumb needs a yourthemename_breadcrumb function in the template.php. You may take a look at the template.php of the Zen theme. It's well documented. (btw, it's similar with Drupal 5, but you have to use different naming conventions)
Some warning note: don't remove check_plain, if you have user contributed content. You will open a security hole.
Best regards
Edmund
----------
I do Drupal Modules, Theme Development and Migrations. Send a private message or visit http://katp.de (a german site) and let's see, if i can help you.
php5 and htmlspecialchars()
The problem really seems to be that when the title is run through check_plain, it gets passed to htmlspecialchars() which encodes the ampersand in any existing html entities. So, a character code like ™ () becomes &#153.
In php 5.2.3 or higher, htmlspecialchars() has a double_encode flag which you can set to false, and it won't encode existing html entities.
So, if you're writing a preprocess function in your template.php file, and you're running php 5.2.3 or higher, you can still pass all the values to htmlspecialchars(), just set the double_encode flag to false.
edit: I was having some trouble with this in some modules I was developing. I eventually traced the double encoding back to my custom title functions in which I was returning strings processed by t(). t() was encoding them and then drupal was double encoding them. The only way to get around it was to not use t() on the title. (it feels so wrong! ;)) My previous suggestion is still useful - especially if you're getting pre-encoded strings to use in the title, like from a database.
All the best,
Emily
Hello,
Hello,
I had the same issue on a drupal 7 website, I used #2 on page.tpl.php, it worked but I got this message:
I only replaced this:
<?php if ($title): ?><h1 class="page-title"><?php print $title; ?></h1><?php endif; ?>
for this
<?php if ($title): ?><h1 class="page-title"><?php print $node->title; ?></h1><?php endif; ?>
What do I have to change to fully correct it?
I checked phptemplate.engine but there nothing about $title, I guess in Drupal 7 the function is set somewhere else?