Conditional Tags
From Textbook
Deprecated page! Page will be kept until content is recycled, then terminated.
Contents |
Overview
Conditional tags allow one page or form template to display different elements depending on how the template is used. Code inside a conditional tag is only executed if the conditions of the tag are true. Some conditional tags have an "else" feature that will execute code only if the conditions are false.
Granted that's not the clearest description (it could be better) so here's a few code examples to help it along:
Display different navigational links on individual article and article list pages
<txp:article /> <txp:if_individual_article> <p><txp:link_to_prev>Previous article</txp:link_to_prev></p> </txp:if_individual_article> <txp:if_article_list> <p><txp:older>Older articles</txp:older></p> </txp:if_article_list>
Use special formatting for all the articles by a specific author
<txp:if_article_author name="the-wizard"> <txp:article form="wizard-form" /> <txp:else /> <txp:article /> </txp:if_article_author>
Nesting
Conditional tags may be nested, unless you are nesting a tag within the same tag.
For example, these will work:
<txp:if_section> I'm looking at a particular section. <txp:if_category name="oranges"> I'm also looking at the category named "oranges". </txp:if_category> </txp:if_section>
<txp:if_custom_field name="apples"> apples! </txp:if_custom_field> <txp:if_custom_field name="oranges"> oranges! </txp:if_custom_field>
These will not work:
<txp:if_custom_field name="apples">
apples!
<txp:else />
<txp:if_custom_field name="oranges">
oranges!
</txp:if_custom_field>
</txp:if_custom_field>
Conditional Article Tags
- <txp:if_article_list> ... </txp:if_article_list>
- <txp:if_individual_article> ... </txp:if_individual_article>
- <txp:if_first_article> ... </txp:if_first_article>
- <txp:if_last_article> ... </txp:if_last_article>
- <txp:if_different> ... </txp:if_different>
- <txp:if_article_section> ... </txp:if_article_section>
- <txp:if_article_category> ... </txp:if_article_category>
- <txp:if_section> ... </txp:if_section>
- <txp:if_category> ... </txp:if_category>
- <txp:if_excerpt> ... </txp:if_excerpt>
- <txp:if_custom_field> ... </txp:if_custom_field>
Conditional Comments Tags
- <txp:if_comments > ... </txp:if_comments>
- <txp:if_comments_allowed > ... </txp:if_comments_allowed>
- <txp:if_comments_disallowed > ... </txp:if_comments_disallowed>
Conditional Search Tags
- <txp:if_search> ... <txp:else /> ... </txp:if_search> double conditional tag to allow you to customise search results template and main page, even if both share the same template




