Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#2 2011-07-02 12:25:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,448
Website GitHub

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

#4 2011-07-02 13:54:21

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

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

#6 2011-07-17 10:55:33

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

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

#8 2011-07-17 11:54:29

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#9 2011-07-18 07:07:31

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

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

Board footer

Powered by FluxBB