Textpattern tips, tutorials and code snippets

New container tags

Textpattern 4.07 introduced many new features, one of which is the container tag capacity for various tags.

While updating one of my sites the other day I decided to update the code to utilise the new container tag format. It may be of use to others updating their own code.

Previous method

In the old site, we used this code in the page template, with a call to a form for processing:

<txp:article_custom section="players" form="players_list" wraptag="ul" break="li" class="category_list" />

Form players_list:

<txp:permlink><txp:title /></txp:permlink>

New method

<txp:article_custom section="players" wraptag="ul" class="category_list" limit="20">
<li<txp:if_article_id> class="active" </txp:if_article_id>><a href="<txp:permlink />"><txp:if_article_id>&raquo; </txp:if_article_id><txp:title /></a></li>

The above is placed in your page template. The code has been extended by adding a class="active" to the li item, as the code is used as a sub-menu in the sidebar, and we want our visitors to have an idea of where they are.

As you can see in the new method, there is no need for a form to process the tag attributes – this is the main difference between single and container tags. To quote TextBook:

Container tags are used when something has to be enclosed by tags instead of being replaced by them.

The above example is simple but should give you an idea of how to use the new container tags. There is less code and arguably the control over output is placed where it belongs – in the page template. Forms offer excellent functionality, but are best used in situations where you need something like a server-side include, not for processing article tags. Thanks to the developers of Textpattern, we are now able to do this.

4 Comments Comment feed

Quality control: @</txp:article>@?

Thanks Markus – good catch! The </txp:article> is now </txp:article_custom>

Shucks, I don’t get why this works:

<txp:if_article_id> class="active" </txp:if_article_id>

Why is class="active" output when we are viewing that particular article?

Hi Nora, check the Docs entry for if_article_id – quote:

The tag will execute the contained statement if the article id associated with a particular article matches the id attribute.

What this means is it checks if the article id is the same as the id in the URL! Hope that helps…

Add a comment

Use Textile help to style your comments