Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-07-02 12:12:08
- Dimitri
- Member
- From: Johannesburg
- Registered: 2010-10-31
- Posts: 129
New conditional tag
I was thinking it would be nice if we had something like this
<txp:if_no_results>
</txp:if_no_results>
We can use this conditional for displaying a message in the case when no entries are returned. The contents inside of the conditional will be displayed in cases where there are no results returned for the tag.
This tag would have the ability to work on any container tag and including any plugins.
For example:
<txp:article>
<txp:if_no_results>
<h2>No entries available</h2>
</txp:if_no_results>
<h2><txp:title /></h2>
</txp:article>
and this if there is no upcoming events, instead of using the difficult <txp:if_variable>
<txp:smd_article_event section="events" limit="4" time="today, future">
<txp:if_no_results>
<h2>Noupcoming events available</h2>
</txp:if_no_results>
<h2><txp:title /></h2>
</txp:smd_article_event>
This idea comes from working on expressionengine, it basically works on anything…. Anything….
Last edited by Dimitri (2011-07-02 12:15:10)
<txp:way_too_cool />
Offline
Re: New conditional tag
Converting tags to use <txp:else />
is more Textpatternish and less expensive in terms of performance (because things don’t have to be evaluated twice, unlike with your proposed syntax). I could probably retrofit smd_article_event with <txp:else />
if I put my mind to it.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#3 2011-07-02 12:28:40
- Dimitri
- Member
- From: Johannesburg
- Registered: 2010-10-31
- Posts: 129
Re: New conditional tag
Understood… For now, I can suffer a little with the <txp:if_variable>
tag :P
<txp:way_too_cool />
Offline
Re: New conditional tag
There is chh_if_data but the general opinion is that using txp:variable is much more efficient because it is targeted. You just have to think more about how you use it. Did you get anywhere further with this?
TXP Builders – finely-crafted code, design and txp
Offline
#5 2011-07-17 10:39:47
- Dimitri
- Member
- From: Johannesburg
- Registered: 2010-10-31
- Posts: 129
Re: New conditional tag
Hi Jakob…
I havent had the chance to try out the advices you gave me. I have already moved onto other site.
I will let you know if I have achieved anything.
Thank you
<txp:way_too_cool />
Offline
Re: New conditional tag
Hi Dimitri
would this help?
<txp:variable name="hasarticles" value='<txp:article>' />
<txp:if_variable name="hasarticles" value="">
<h2>No entries available</h2>
<txp:else />
<txp:article>
<h2><txp:title /></h2>
</txp:article>
</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
#7 2011-07-17 10:58:52
- Dimitri
- Member
- From: Johannesburg
- Registered: 2010-10-31
- Posts: 129
Re: New conditional tag
Hi Colak.
I dont have problems with this
Have a look at this link
It was for smd_calendar plugin
Everything is sorted but I was doing trying to do some more advanced with Jakob advices. I will try find time to try it out
<txp:way_too_cool />
Offline
Re: New conditional tag
Variable tags have one nice feature; container tag mode. Which can make the syntax easier to read as no quote escaping and likes is needed. When returning the results (if any) it’s best to use the variable tag that holds the results instead of doing new database query. Using colak’s example as starting point, i.e.
<!--
Populate variable named 'articles'
with list of articles
-->
<txp:variable name="articles"><txp:article>
<h2><txp:title /></h2>
</txp:article></txp:variable>
<!--
Check if the variable named 'articles'
has any contents. If has, return the list of
articles using the variable.
-->
<txp:if_variable name="articles" value="">
<h2>No entries available</h2>
<txp:else />
<txp:variable name="articles" />
</txp:if_variable>
Last edited by Gocom (2011-07-17 11:56:34)
Offline
Re: New conditional tag
IMHO the container mode should be mentioned more explicit in the txp:variable tag documentation examples.
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline