Part three of my five part series on Textpattern CMS navigational tags focuses on three intriguing tags that, frankly, I don’t use as often as I should. There’s a scene in the movie Léon where the hitman visits his handler to collect a weapon for training purposes. That’s my reason for wheeling these three tags out today; you’ll learn something new, and I’ll refresh my skills. These are the tags in question:
The `link_to_home` is a curious one in that it can be used as single or container tag, but is far more useful as a container. With its single attribute (css=”CSS class name”), there’s not much in the way of customisation available within the tag itself. Using `link_to_home` in its single container guise outputs a hyperlinked URL to the Textpattern site:
This is almost the same as using `site_url` without the hyperlinked stuff, though it can be built-on to achieve the same thing. This code is more verbose, but does the same thing as `link_to_home`:
<a href="<txp:site_url />"><txp:site_url /></a>
The other two tags, `link_to_next` and `link_to_prev`, are also in the One Attribute Textpattern Tag Club (it’s a thing that I’m starting this year). These tags are used to navigate between individual articles: `link_to_next` generates the URL for the next article in the list, and `link_to_prev` does the same thing for the previous article. Now you know what the tags do, the sole attribute is `showalways` (boolean value, defaults to 0) and is more readily understood: the most recent article won’t ever have a newer article to link to, by definition. The same goes for the oldest article – there is nothing older than oldest (that got deep and meaningful, woah).
In these instances, using a vanilla `link_to_next` or `link_to_prev` respectively will do nothing – it will be ignored. However, when `link_to_next` and `link_to_prev` are used with `showalways=”1″`, they will always be processed. This can lead to some confusing user interface elements, so be absolutely sure you know what you’re doing if you roll this out.
Although `link_to_next` and `link_to_prev` are basic in their use (i.e., they spit out a URL), they can be wrapped in extra things to make them more useful. For example:
This is `link_to_prev` being used as a container/wrapper, and the innards are generated by the `prev-title` tag. This generates a hyperlinked article title, and in the context of an article form, it’s dynamic to each article. The gotcha you need to be careful of with both of these tags is demonstrated in the following example:
<txp:link_to_next showalways="1"><txp:next_title /></txp:link_to_next>
Where the article is the newest (i.e., most recent), `next_title` won’t return anything, so nothing will be shown to the visitor. Likewise, the `link_to_next` doesn’t have anything to extract a URL from, so won’t generate anything. In the years I’ve been using and deploying Textpattern, I haven’t ever had an occasion to use `showalways`, and should that situation arise I will be very happy to share feedback with you.