Textpattern CMS conditional tags: an overview

admin-ajaxThis is the second chapter of my six part series on Textpattern tags. The focus this month is conditional tags. Conditional tags use logic to decide the outcome of a given situation, and can be as simple or complex as you decide to go. If there’s such a thing as a tag rabbit hole, conditional tags are a good contender. There are currently 33 tags considered to be conditional-type tags:

  • <txp:else />
  • <txp:if_article_author />
  • <txp:if_article_category />
  • <txp:if_article_id />
  • <txp:if_article_image />
  • <txp:if_article_list />
  • <txp:if_article_section />
  • <txp:if_author />
  • <txp:if_category />
  • <txp:if_comments />
  • <txp:if_comments_allowed />
  • <txp:if_comments_disallowed />
  • <txp:if_comments_error />
  • <txp:if_comments_preview />
  • <txp:if_custom_field />
  • <txp:if_different />
  • <txp:if_excerpt />
  • <txp:if_expired />
  • <txp:if_expires />
  • <txp:if_first_article />
  • <txp:if_first_category />
  • <txp:if_first_section />
  • <txp:if_individual_article />
  • <txp:if_keywords />
  • <txp:if_last_article />
  • <txp:if_last_category />
  • <txp:if_last_section />
  • <txp:if_plugin />
  • <txp:if_search />
  • <txp:if_search_results />
  • <txp:if_section />
  • <txp:if_status />
  • <txp:if_variable />

With the exception of the `<txp:else />`, all the conditional tags begin with `<txp:if_` and most are pretty straightforward to understand when you know the building blocks of Textpattern CMS.

Tags have been introduced into Textpattern over a number of years, mostly in response to user feedback and requirements. Each of the tags listed above are covered by the core code; plugins can (and do) extend the functionality of Textpattern further, often with their own plugin-specific tags that you won’t see listed above.

I’ve selected 4 tags from the above list that I will explain in more detail, with examples. I consider these four a solid introduction to conditional tags, and knowing them will set you in good stead for learning the other tags. There is considerable crossover in the way conditional tags work, although their respective attributes vary. Some conditionals have no attributes at all, and others allow you to have very specific control over what can be outputted.

The first tag I’m going to cover is `<txp:else />`. It’s absolutely vital you know how to use it correctly, because it allows you to exercise a lot more control over your tag constructs. Essentially, knowing how `<txp:else />` connects to the other conditionals will extend the list of things you can check for. At a high level, a conditional tag will do something depending on the outcome of a check. For example, the `<txp:if_expired>` tag checks if the article being viewed has expired. If it has, then something can take place. Like this:

<txp:if_expired>
 do something
</txp:if_expired>

That’s great if you want to `do something` if the article has expired. There is no such thing as the `<txp:if_not_expired>` tag, but the effect can be achieved by using `<txp:if_expired>` and `<txp:if_else />` together:

<txp:if_expired>
<txp:else />
do something
</txp:if_expired>

In this code, a check takes place for the article expiry. If it’s expired, then nothing happens; if it hasn’t expired, the `do something` part comes into play.

One of my favorite parts of Textpattern site building is the tag building part. You have a powerful, flexible engine at your disposal and you don’t need to know how to write PHP to harness it – how cool is that? Over the coming month I’ll be showing you how to better understand conditional tags in Textpattern, and I look forward to telling you more.

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 | Leave a comment

State Server mode in ASP.NET

StateServer mode ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers. In this article I will give you a step-by-step guide on how to use State Server Mode in your ASP applications. Learn More

Tags: , , , , , , , , , , , | Posted under ASP .NET 2, ASP .NET 3.5, ASP .NET 4.0 | Leave a comment

Drupal7: Nodesymlinks Module

David G - DrupalIn a project I’m moving from Drupal6 to Drupal7 the client would like some pages that appear deep within a site to be visible in a Menu at the root of the menu. The deep content is apart of a Book content type. Without using simply a menu alias I was uncertain how to achieve this functionality for 2 pages of the site. Having used this module in the past, I considered NodesymlinkLearn More

Tags: , , , | Posted under Drupal | Leave a comment