Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-06-25 10:08:22
- lonelytraveller
- Member
- From: Firenze, Italy
- Registered: 2008-04-04
- Posts: 45
Conditional to check if article list is not empty?
Hello, maybe it’s a stupid question, but I’ve been trying to find an answer for so long and probably I’m missing some very obvious point… however here’s my problem:
I’m showing a list of articles in a sidebar (it’s an event list) built wit a simple article_custom tag: <txp:article_custom time="future" limit="5" section="events">
that’s the easy part.
Here’s the difficult part: if the list is empty (that is there’s no event on schedule) then I want a short message to be displayed.
Is there any (easy) solution? I just need to find a way to check if the list is empty (or from another perspetctive if there’s at least one article in the list) but no textpattern conditional tag seems to fit my needs.
Any suggestion would be greatly appreciated.
Offline
Re: Conditional to check if article list is not empty?
Hi Caterina
here’s an untested one:)
<txp:variable name="hasarticles" value='<txp:article_custom time="future" limit="1" section="events" />' />
<txp:if_variable name="hasarticles" value="">
<p>your short message here</p>
<txp:else />
<txp:article_custom time="future" limit="5" section="events" />
</txp:if_variable>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Conditional to check if article list is not empty?
Another one, using the plugin chh_if_data
<txp:chh_if_data>
<txp:article_custom time="future" limit="5" section="events" />
<txp:else />
your short message
</txp:chh_if_data>
Offline
#4 2011-06-25 11:28:37
- lonelytraveller
- Member
- From: Firenze, Italy
- Registered: 2008-04-04
- Posts: 45
Re: Conditional to check if article list is not empty?
Colak thanks for reminding me of the @txp:variable tag, I usually forget to use it, but it would make my life much easier. I tested your untested solution and it works like a charm :-)
CeBe thanks for the suggestion, I’ve never used this plug-in but I’ll test your solution too.
Last edited by lonelytraveller (2011-06-25 11:28:57)
Offline
#5 2011-06-25 20:25:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Conditional to check if article list is not empty?
chh_if_data does about the same, but it is less flexible than the variable/if_variable combo. And the plugin is not maintained anymore (though it still works).
Offline
Re: Conditional to check if article list is not empty?
chh_if_data is an oldie but goldie :)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: Conditional to check if article list is not empty?
cough chh_if_data functionality should be core cough
Offline
Re: Conditional to check if article list is not empty?
mrdale wrote:
cough chh_if_data functionality should be core cough
If one wants to use it, use it. It’s available as a plugin, and adding it to the core wouldn’t change how it works. Core has its big brother, variables. More flexible, fast, easy to use and doesn’t share the limitations.
Offline
Re: Conditional to check if article list is not empty?
Gocom a écrit:
Core has its big brother, variables. More flexible, fast, easy to use and doesn’t share the limitations.
Right. So, to take full advantage of speed, let’s use hasarticle
variable this way and avoid a second database request :
<txp:variable name="hasarticles" value='<txp:article_custom time="future" limit="1" section="events" />' />
<txp:if_variable name="hasarticles" value="">
<p>your short message here</p>
<txp:else />
<txp:variable name="hasarticles" />
</txp:if_variable>
Offline
Offline