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.

comments powered by Disqus