textpattern ~ code ~ css

Jul 20 2007

Plugin: mg_setheader

The plugin <txp:mg_setheader /> allows one to change/specify the header for any textpattern page. By default, textpattern delivers section pages as text/html. This plugin can be used to serve up a valid RSS feed from a standard page template.

Download it: <txp:mg_setheader />


This plugin takes two attributes:

  • name: Defaults to ‘Content-Type’
  • value: Defaults to ‘text/xml’


Example #1:

<txp:mg_setheader name="Content-Type" value="application/rss+xml" /><?xml version="1.0" encoding="UTF-8"?> 
(and so on...) 

The above example would be used on a page template and would set the header for that page to the spec’d value. In the above example, you could generate a valid RSS feed using the appropriate RSS tags (see the RSS spec for more information) and standard textpattern tags. This would allow you to insert images, create podcasts (see my tutorial Podcasting With Textpattern), and place images at the top of your feeds.

Example #2:

<txp:mg_setheader /><?xml version="1.0" encoding="UTF-8"?> 
(and so on...) 

The above example simply sets the header to ‘text/xml’ (which is an equally valid header for an RSS feed).

Notes on usage

This plugin is most commonly used to generate an RSS feed from a standard Textpattern page template. When you do this, <txp:mg_setheader /> must reside AT THE VERY TOP OF YOUR PAGE TEMPLATE, and the opening <?xml> tag must follow IMMEDIATELY behind it (i.e. no linebreak, no space between the <txp:mg_setheader /> tag and the opening <?xml> tag).


I’d love to take credit for this, but the code belongs to Sencer. I gleaned this from a post in the textpattern forum. I can’t seem to find the thread, otherwise I’d post a link here.

Posted in text on July 20, 2007

3 comments added

Commenting disabled.


Welcome to the Text archives. This is where I write about Textpattern, a lightweight, PHP-based content management system.

side image

Textpattern Plugins

I've made a few plugins for Textpattern that provide very modest additions to the software's existing functionality. Here they are: