XHTML tags in article titles [revised]
Thanks to whatbrick’s post I finally have a method that makes it possible to inject <br /> or <span /> or any other XHTML-tag into the article’s title field without showing these tags on the page.
But when viewing an individual article’s page Textpattern composes <txp:page_title /> from the sitename plus the article’s title, and then at the latest I’d find all my spans and breaks in the window title.
Here’s what I did:
1.
In the advanced preferences tab I created a custom field named “unedited_title“.
2.
To generate the title tag in the head portion of my page template I replaced the typical <title><txp:title /></title> by <txp:output_form form="html_head_title" />, the form “html_head_title“ containing the following:
<title><txp:if_individual_article>
<txp:if_custom_field name="unedited_title">
<txp:sitename />: <txp:custom_field name="unedited_title" />
<txp:else />
<txp:page_title />
</txp:if_custom_field>
<txp:else />
<txp:page_title />
</txp:if_individual_article></title>
[Note: Remove the line breaks before saving the form. They are here for clearness but might cause troubles in some browsers]
3.
In all of my article forms where I wanted to display the styled title I replaced txp:title by <txp:output_form form="txp_title_new" />. In the form “txp_title_new“ I stored whatbrick’s php snippet:
<txp:php>
global $thisarticle;
echo $thisarticle['title'];
</txp:php>
4. (optional)
Wherever I’d previously used <txp:title /> inside XHTML tags like <img alt="<txp:title>" ... /> or <a title="<txp:title />" ... /> I replaced it by <txp:output_form form="tag-internal_title">, calling a form provided with the following content:
<txp:if_custom_field name="unedited_title">
<txp:custom_field name="unedited_title" />
<txp:else />
<txp:title />
</txp:if_custom_field>
Done.
Now, whenever I want to style parts of a headline or have to insert line breaks, I copy the original title, paste it in the “unedited_title“ field, and can insert the necessary XHTML tags in the article’s title field. They won’t show up any longer, neither in the page nor in the window’s title bar or in links’ titles.
[Revision note: Unlike the first version of my tip the revised method doesn’t produce errors in test mode, in no situation, so you can focus better on eliminating other faults.]









Comments/questions? Leave a message in the form.
Commented (3)
Great tip. I am wondering why step 3 is needed, are the problems with doing just step 4 instead of step 3?
3 is used for displaying the styled title.
Good that you’ve asked, Alannie, so I became aware of how to improve the according sentence a little.
Thanks for this article, it’s great. So great that we’ve made it ‘sticky’ on The Webmaster Forums. Now we don’t have to repeat ourselves, just send people to this article!
Subscribe to this article's comments RSS feed. [ ? ] View Recent Comments across the site.