Use of new tag if_variable to replace chh_if_data
As a follow up to our previous TXP Tip on Custom content if data exists, the latest version of Textpattern – 4.07 – allows us to replace the plugin with native functionality.
The original code
Lets take a look at some of the original code from the article:
<h2>Site Announcements</h2>
<txp:chh_if_data>
<txp:article_custom section="news" form="news_announcement" category="Announcements" limit="1" />
<txp:else />
<p>There are no current announcements.</p>
</txp:chh_if_data>
Introducing if_variable
With the new if_variable tag introduced in 4.07, we no longer need chh_if_data. Instead, we can use this code, placed early in your page (before you need to display the results):
<txp:variable name="if_announcements" value='<txp:article_custom section="news" form="news_announcement" category="Announcements" limit="1" />' />
Displaying the results
Further down the page, lets take a look at the results:
<txp:if_variable name="if_announcements" value="">
<p>There are no current announcements.</p>
<txp:else />
<txp:article_custom section="news" form="news_announcement" category="Announcements" limit="1" />
</txp:if_variable>
Your usage may vary, but the method should be clear.
3 Comments - Comments RSS Feed
Luca Sabato | nope
# 26 March 2009
IMHO…
if_variabile tag is more different to the plugin, require an addition step to work, i hope in the next realese 4.0.9 the team add one new tag “if_data” to replace the useful plugin :)

Markus Merz | Hamburg St. Georg
# 16 March 2009
For better understanding I would reduce the code to the skeleton functions or add simple comments in the code:
# set variable ** In this case calling the output of a TXP tag by using single quotes # use variable in an empty/filled situation ** value=”“ = empty
In this example also the usage of name=“if_anouncements” is disorienting.
Don’t use proverbs!
Instead, with Textpattern >4.0.7 it is possible to set a variable first with @<txp:variable name=“variable” value=“value” />@. After setting the variable a second step using a @<txp:if_variable …> container makes it possible to create different output like in every other TXP @<txp:if_…>@ condition.
PS: Where is the textile for comments?