Custom RSS in Textpattern
Part Two: Escaping special characters
In this article, I’ll just be fixing a minor annoyance left at the end of Part 1.
I recommend reading Part One first, or at least copy the page and forms we’ll be modifying here.
Part of what I’m doing will use atb_rss_tags. This ridiculously-simple plugin simply makes three of PHP’s string-manipulation functions available as Texpattern tags: strip_tags(), htmlspecialchars(), and trim().
Here I use <txp:htmlspecialchars> to fix one irritation from last time: the validation error which occurs when a special character, such as “&” appears in a title, site motto, etc.
Last time, I did this in my RSS page:
<description><![CDATA[<txp:site_slogan />]]></description>
Which is probably fine. But using htmlspecialchars is more in line with what Textpattern does with its standard RSS feed:
<description><txp:atb_html_special_chars><txp:site_slogan /></txp:atb_html_special_chars></description>
Which turns, for example, “@&@” into “@&@”, generating correct XML. It might also be a good idea to use this on your article form, in the title tag, in case you use any forbidden characters in your article titles:
<title><txp:atb_html_special_chars><txp:title /><txp:atb_html_special_chars></title>
Field Reports:
Commenting is closed for this article.

Subscribe to the Daydream Lab [RSS]