Get familiar with Textpattern CMS `section` and `section_list` tags

admin-ajaxFor the fifth and final part of this series on Textpattern navigational tag specifics, the time has come to cover a couple of tags that deal with sections, specifically:

  • `section`
  • `section_list`

Both of these tags have a bunch of attributes. Attributes are used to fine-tune the actions taken when a tag is used in Textpattern. I’ll start with `section`, which has these attributes and defaults:

  • class=”CSS class name” (default: unset)
  • link=”boolean” (default: 0, single tag only)
  • name=”section name” (default: unset, current section)
  • title=”boolean” (default: 0, display the name)
  • url=”boolean” (default: 0, title or full link depending on `link` setting)
  • wraptag=”HTML tag” (default unset)

If you’ve been reading along with the current series of tag explanations, you’ll likely be familiar with all of the above attributes; there’s nothing new. What’s interesting here, though, is that there are attributes which take actions based on the settings of other attributes in the same tag. For example, the `url` attribute will output either a plain URL or a hyperlink, depending on how the `link` attribute has been set. Bear in mind that `link` can only be used in a single tag instance, you should use `url` if you deploy `section` in a container context.

Does that make sense? Perhaps some examples will help. This outputs the section name:

<txp:section />

Note: section name, not section title. The title is typically prettier than the name. The name is what’s used in building URLs. If you want to show the title, then add the `title` attribute:

<txp:section title="1" />

Want to link it? Sure:

<txp:section link="1" title="1" />

How about a linking to a nominated section and putting an HTML wrapper around it, does that sound fun? I can tell you – anything Textpattern-related is super fun. Here’s how you do all that:

<txp:section link="1" name="fruit" title="1" wraptag="span" />

With that last example, a similar thing can be achieved with a container tag construct:

<txp:section name="fruit" url="1" wraptag="span">Fruit</txp:section>

Note the absence of `link` and the presence of `url`. If you want to build a list of section links, it’s pretty straightforward to use `section_list` and let it do most of the heavy lifting. It has some attributes that permit some fine-tuning:

  • active_class=”CSS class name” (default: unset, single tag only without the `form` attribute)
  • default_title=”default section title” (default: the site name, only when `include_default` is set to 1)
  • exclude=”section name(s)” (default: unset)
  • form=”form name” (default: default form)
  • include_default=”boolean” (default: unset)
  • sections=”section name(s)” (default: unset, all sections)
  • sort=”sort value(s)” (default: name ascending, alphabetical order)

The clever stuff starts when `section_list` uses `section` to generate lists. For example, consider this code:

<txp:section_list break="li" form="section_sidebar" label="Sections" wraptag="ul" />

This will churn out a list of sections in an unordered list, with each entry as a list item, using the form `section_sidebar` to build each individual item. The `section_sidebar` form could look like this:

<txp:section link="1" title="1" />

And, presto, you’ve just made a section list with individually-generated sections. Good job.

Next time: I’ll be starting my series about markup tags in Textpattern CMS. You should come back and check it out, it’ll be amazing.

Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!

Tags: , , , , , , , , , | Posted under Textpattern | RSS 2.0

Author Spotlight

Pete Cooper

Pete Cooper has been using Textpattern since 2005. Textpattern is his preferred CMS weapon of choice. Its logical and flexible approach to content management makes Pete happy, as does its lightweight core and helpful user community. Pete's website - - runs on top of Textpattern and chronicles his day-to-day experiences from his home near the Atlantic in north Cornwall, United Kingdom.

Leave a Reply

Your email address will not be published. Required fields are marked *