Simplifying common section content in Textpattern
Posted on November 04, 2008 in Web Design and Textpattern. - No comments
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.
Previous: Discovering Zenith Next: Problems with Digitiser Drift on a Palm TX
Related Articles
Recent Articles in Technology
- Tackling Comment Spam in Textpattern
- TealOS killed by Palm
- HandyShopper
- Problems with Digitiser Drift on a Palm TX
- Simplifying common section content in Textpattern