Enter HTML into an article title
There are many instances where an author might want or need to add a bit of HTML to an article title. For example, to hard code a break:
<h2>My Story <br />Is Better Than Yours!</h2>
or if a title of the book is contained within:
<h2>I reviewed <cite>A Tale of Two Cities</cite></h2>
Since you cannot use Textile in the title field, you might be tempted to simply insert your HTML, but that would result in this showing up on the page:
I reviewed <cite>A Tale of Two Cities</cite>
and this in the underlying html:
I reviewed <cite>A Tale of Two Cities</cite>
The Solution
The solution is to:
- Use a placeholder for the html elements you want
- Use a bit of php to output the title
For our title example, you could enter the title as:
I Reviewed {A Tale of Two Cities}
and then use this in your article form to output the title:
<h2><txp:permlink><txp:php>
global $thisarticle;
assert_article();
$my_title = str_replace('{', '<cite>', $thisarticle['title']);
echo str_replace('}','</cite>',$my_title);
</txp:php></txp:permlink></h2>
Using a placeholder is important so that the titles in your RSS feed or output into the html <title> element don’t contain html elements.
Thanks to jsoo on this thread for the tip!

jsoo
# 20 June 2009
You could even use this workaround to use Textile in article titles. Just bear in mind the caveats pointed out in the Txp forum thread linked above — it’s up to you to make sure the raw Textile looks OK in RSS feeds, etc. Obviously the Txp team have decided that Textile in article titles is Not, On Balance, A Good Thing, so be advised.
You could do this by replacing <txp:title /> with:
<txp:php>
global $thisarticle;
assert_article();
include txpath.’/lib/classTextile.php’;
$txt = new Textile;
echo $txt->TextileThis($thisarticle[‘title’]);
</txp:php>
Naturally you’d want to put this in a form if you want to use it more than once.