Go to content Go to navigation Go to search

Simplifying common section content in Textpattern

It’s pretty common to have common content that is specific to each section. Often this takes the form of different side-bar content. This is easy to accomplish in Textpattern by creating a form for each section and then including the following code in your page template:

<div id="side"
<txp:if_section name="articles">
	<txp:output_form name="side_articles" />
</txp:if_section>

<txp:if_section name="features">
	<txp:output_form name="side_articles" />
</txp:if_section>

<txp:if_section name="default">
	<txp:output_form name="side_default" />
</txp:if_section>
</div>

This is obviously rather long winded, and as you add more and more sections to your site, it becomes increasingly clumsy. Textpattern 4.0.7 promises us the ability to include tags within tags which would provide a solution along the lines of:

<txp:output_form name="side_<txp:section name="1"/>"/>

The problem with this is that there will be an error if the current section does not have a pre-defined form.

rah_output_section_form

There’s a simple solution to this problem in the form of the rah_output_section_form plugin by Jukka Svahn.

<txp:rah_output_section_form prefix="side_" />

This will automatically display a form “side_section name“. Nothing will be displayed if a form for the current section hasn’t been created.

As well as simplifying the required code, the rah_output_section_form plugin also has another advantage. It’s possible to provide the plugin with a default form that will be displayed if there isn’t a specific section form.

<txp:rah_output_section_form prefic="side_" default="defaultside" />

Jukka has recently mentioned that he may add another parameter to do the same for category contexts. Something that I’ll find particularly useful.


  Textile Help

Related Articles

Recent Articles in Technology

Subscribe