The Hickensian
2.12.05 Textpattern Notes: New Tag goodness
Back when Texpattern was still gestating, many plugins were written to fill holes in its templating options, but its come a long way since then. Every day I’m finding new tags that allow me to keep plugins down to a minimum.
If you haven’t already, you really need to bookmark these pages: Alphabetical Tag Listing and Attributes Cross Reference on the Textpattern wiki documention, called “TextBook”. This an amazing resource, especially if you adopted Textpattern back in the days when it had no documentation. There are lots of gems in here, so I thought I’d dig some out, in case they’re new to you as well.
Conditional Comments
I think the area where the 4.0-4.02 releases really shone were in the wealth of conditional tags. Here’s an example:
<txp:if_excerpt>
<blockquote>
&;ldquo; <txp:excerpt />”
</blockquote>
</txp:if_excerpt>
There are also conditional tags to test for categories, comments, whether comments are open, whether you’re viewing the last article and more. Check out all the tags that start with txp:if_ on the list. The section conditionals are very handy, as you can specify either a single section, or a range (make sure that you don’t have any spaces inbetween the section names, just commas). Here’s one from my templates:
<txp:if_section name="journal,destinations,archive">
...content...
</txp:if_section>
I use this one to output the correct submenu in each section. If you want to specify the homepage (or ‘default’ page as its known), leave the attribute blank like so:
<txp:if_section name="">
...content...
</txp:if_section>
To specify the homepage as part of a list, use a comma at the start:
<txp:if_section name=",journal,archives">
...content...
</txp:if_section>
Also Very Useful™, are the custom field conditionals. In my portfolio section, some of the entries are websites and have a URL associated with the information. This is done using a custom field (set up in preferences > advanced preferences) and used in the article form like this:
<txp:if_custom_field name="URL">
<a href="<txp:custom_field name="URL" />" title="Visit <txp:title />"><txp:article_image /></a>
</txp:if_custom_field>
This creates a link to the site around the main portfolio image.
Finally, to complete the usefulness, the devs have added a <txp:else /> conditional, to help keep code down. Here’s an example:
<p>
<txp:if_excerpt>
<txp:excerpt />
<txp:else />
Sorry, I couldn't be bothered to write an excerpt...
</txp:if_excerpt>
</p>
Permalinks & Single Tag mode
Until recently I was using the zem_link plugin to allow custom class names and title attributes on permalinks. It was one of the things that I didn’t like about TXP compared to Moveable Type – it outputted the XHTML for you. However, I found this on the description page for the permalink tag:
By default permlink returns only a very basic link, which doesn’t allow for customizing the link title, or adding a CSS class, etc. Using the tag in its Single Tag capacity opens up a lot more possibilities. For example, to have the permanent link have an HTML title attribute of the article’s title, and also apply a class to it named “orange”:
<a href="<txp:permlink />" title="<txp:title />" class="orange"><txp:title /></a>
Thats what I’ve been wanting! I had no idea that the tag could be used that way.
Offset
Another feature I missed from Moveable Type days was the ability to output a list of articles, offset by a specified number first. This is now part of the article tag attribute options:
<txp:article form="recent" sortby="Posted" sortdir="desc" offset="3" limit="5" />
I use this on my journal homepage, showing the last 3 posts in full, and then the 5 posts thereafter as just links. The list of previous articles can now exclude the last 3, as these are shown in full. For individual article pages however, we need to show all the articles, so of course I use conditional tags :
<txp:if_article_list>
<txp:article form="recent" sortby="Posted" sortdir="desc" offset="3" limit="5" />
<txp:else />
<txp:article form="recent" sortby="Posted" sortdir="desc" limit="5" />
</txp:if_article_list>
Which neatly wraps it all up! One of the reasons I love Textpattern over other options so much, is its templating tags. The xml style makes so much sense, and easy to grasp.
Recent Posts
26.01.10 The Handbag has been raised!
22.01.10 Guide to the Internet (2000)
20.01.10 Designer, not a construction worker
19.01.10 Why you can never work 'full time'
16.01.10 Dream Report: Look at the Hygiene!
Or Full Archives
The Hickensian is the journal of Hicksdesign, a creative partnership of Jon & Leigh Hicks. Read more about us.
playlist
Hickr | RSS
Contact
Hicksdesign
Island House
Lower High Street
Burford
Oxfordshire, UK
OX18 4RR
+44 (0)7917 391 536
I am currently working full-time with Opera, and not taking on any new projects
29 comments
Journal RSS Feed





Download vCard
Comments | RSS
∞ Ray said 1530 days ago:
Thank you so much for pointing out the new features in Textpattern! I really had no idea about all the improvements, even though I’m a Textpattern user myself. The list offset by number looks very promising. I wish I’d seen that earlier.
∞ David Hemphill said 1530 days ago:
I would like to echo the thanks on the highly informative article, Jon. I had been meaning to look into all the new features of the Textpattern’s latest release but I hadn’t gotten around to it. Thanks for saving me the trouble.
∞ Joel Dueck said 1530 days ago:
The new if_different tag also allows you to chuck the rss_suparchive plugin – see this snippet.
∞ Andrea said 1530 days ago:
Wow thanks! I didn’t know about that use of the permalinks tag either.
I also like what they have done with the comments recently, allowing previews to be placed specifically in the templates, rather than always appearing at the top of the article, and adding labels to the default comment form. TXP is really a nice tight package now, IMO.
∞ Jon Hicks said 1530 days ago:
Joel – thanks for that. I’d never really understood what that tag was for until now.
∞ Kev mears said 1530 days ago:
The textbook resources are invaluable when thinking about how to achieve things in textpattern. The site I’m building at the moment, uses custom fields to sort excerpts on list pages, and two of Mary’s great plug-ins to associate images and files with articles.
I think textpattern is enabling very flexible development. It seems to take less work now to create a site that isn’t so blog-like.
The biggest hurdle for me in textpattern was/is remembering what you can do in forms and what you can do in pages.
∞ eric said 1530 days ago:
Textpattern’s a really solid system, and it keeps getting better. Thanks for the pointers on the tags!
∞ Nathan Smith said 1530 days ago:
My favorite feature in 4.0.2 is by far the new if_comments_preview – I’ve made use of it on both my site and godbit.com to force the comment preview to be at the bottom of the comments list, where it belongs, rather than above the article. So now, the whole process of previewing / submitting is a lot more streamlined, and less disorienting. :)
∞ Justin P said 1530 days ago:
I just found Textpattern a few weeks ago, so I can’t compare it to previous versions. Nonetheless, I am totally in awe of the power of this CMS. The need for plugins is virtually non-existent due to the ever powerful “forms” feature.
The Textbook has been an invaluable resource for me too, though I did hit a few road blocks during initial set-up that kept me guessing for several days. If the Textpattern documentation is great now, I can’t imagine what it was like before (it’s quite sparse).
Thanks for the heads up on the attribute cross ref, a perfect pairing to the tag index.
∞ shafina said 1530 days ago:
thanks for the pointers!
∞ Jon-Michael said 1529 days ago:
Thanks Jon! I just started using textpattern about a week ago (currently breaking all my links…), and have struggled on a few parts. This will certainly help!
∞ Jérémie said 1529 days ago:
Yep, quite some work with the last two, or three, versions. And more goodness to come :)
∞ James Kahlin said 1529 days ago:
Great tips Jon. I’ve been using Textpattern for quite awhile now on my site and I’m surprised to see how much I didn’t know about features that have been around for awhile. I also wasn’t aware of those resources which you linked to. Thanks for that as well.
On a side note, this is my first time commenting on your great site. I’ve been reading your entries for quite awhile though. You always have very intresting writings. Keep up the good work.
∞ Lowell Wood said 1529 days ago:
Thanks for the tips and links jon. I just recently discovered that txp was able to do custom fields and i love it.
∞ Joshua Marshall said 1529 days ago:
Excellent stuff.
Thanks, Jon!
∞ Reinier said 1529 days ago:
Too bad there wasn’t any need for rei_show_custom anymore… ;-)
Thanks for the tip, maybe someday I’ll switch back to TXP from WP.
∞ John Oxton said 1529 days ago:
A life saver for me recently was the if_search tag, having loaded TxP on to a Zeus server where .htaccess seems to be a no go, this tag became a really neccesity for custom search results.
∞ Arjan Terol said 1529 days ago:
Thanks Jon, working with Textpattern for almost 9 months now and I’m still amazed by the power of this little app. To me it’s the first CMS I can fully and truelly customize and let it do the things I want it to do. I have to look into your new notes. Keep them comming!
∞ Anonymous Person said 1528 days ago:
Does anyone know if Blogger.com plans to support tags/categories?
∞ Bastiaan Terhorst said 1528 days ago:
Hey Jon, good stuff, but there’s a problem with your RSS feed.
At least, NewsFire gives a ‘parse error’...
cheers
∞ Peter Parkes said 1525 days ago:
Yeah, I can confirm the parse error in NewsFire at least – I’m not quite sure how to interpret this but it seems like a repeatable problem.
∞ Thomas said 1525 days ago:
This week, I gave TXP a try. Long time ago, I tried to install it, but I got confused with the Presentation system. But, after reading between the lines how the template system works, it is getting more interesting.
I still confused about displaying the “category” archives. My favorite? Lots! And your site is one of my references about enhancing TXP. Thanks Jon!
∞ Erik V. said 1525 days ago:
Shrook also reports an XML error in the feed.
∞ eric said 1523 days ago:
Thomas – you might want to check out Kusor.com’s Textpattern Tags manual – it’s an amazing resource.
∞ Nev said 1522 days ago:
I installed Textpattern yesterday after several years of using my own CMS (handled content just fine, but section and style updates were all manual). Currently, I’m a bit lost in a sea of tags and I can’t find a way to add classes or IDs to my section navigation. I thought I’d found the solution in the above article, but it only appears to work for article links :(
∞ JEL said 1521 days ago:
Great article. Thank you. =)
∞ Stuart said 1519 days ago:
Thanks Jon, you’ve inspired me to seriously consider ditching my own custom cms for Textpattern.
∞ Petr said 1517 days ago:
On IE 6 I see SIDENOTES box below all content. There is maybe css bug with floating box width in your design.
∞ Ivorius for Czech Textpattern said 1515 days ago:
Czech translation is here: http://textpattern.ivorius.com/informace/textpattern-zapisnik-nove-skvele-tagy