Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-10 17:09:44

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Come on, make if_data core

chh_if_data is so simple and elegant a solution to such a variety of situations (effectively superseding specialized ideas like <txp:if_image>) that I think it belongs in the core.

Please? And don’t just dig in your heels and say it’s fine as a plugin. My sites look like a Wyoming sized plugin ranch.

<txp:if_data>
Your criteria turned up an article, Yay!
<txp:article />
<txp:else/>
Nothing to see here, move along...
</txp:if_data>

Offline

#2 2009-03-10 17:14:26

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Come on, make if_data core

You can use if_variable for that now, it even has more possibilities than chh_if_data :)

Offline

#3 2009-03-10 17:27:10

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Come on, make if_data core

Els wrote: You can use if_variable for that now, it even has more possibilities than chh_if_data :)

Yeah, it’s pretty verbose tho, right? Wanna use my example to demonstrate how I’d accomplish the same with if_variable?

Old dog not averse to learning new tricks. ;)

Offline

#4 2009-03-10 17:33:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Come on, make if_data core

<txp:variable name="hasdata" value='<txp:article />' />
<txp:if_variable name="hasdata" value="">
Nothing to see here, move along...
<txp:else/>
Your criteria turned up an article, Yay!
<txp:article />
</txp:if_variable>

There is an example here that does a couple more checks.

Offline

#5 2009-03-10 17:39:24

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Come on, make if_data core

Thanks Els,

Not too shabby I guess. It does call the article tag twice which is a little fugly, but it’ll do the job.

Offline

#6 2009-03-10 18:24:48

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Come on, make if_data core

mrdale wrote:

It does call the article tag twice which is a little fugly, but it’ll do the job.

It’s a workaround and I agree that a generic if_data would be more straight forward, especially for someone new to Textpattern.

Then there are those tags that would deserve an if… sibling like <txp:article_image>.

Offline

#7 2009-03-10 18:54:48

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Come on, make if_data core

So it shall be Martin. :)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#8 2009-03-10 18:57:32

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Come on, make if_data core

mrdale wrote:

It does call the article tag twice

I usually add limit="1", don’t know if that makes much difference though. BTW, I’d think that chh_if_data has to do something similar to calling an article tag to check if there is content, right?

thebombsite wrote:

So it shall be Martin. :)

Yeah, I’d noticed that as well :)

Offline

#9 2009-03-10 19:22:16

FireFusion
Member
Registered: 2005-05-10
Posts: 698

Re: Come on, make if_data core

I and others have requested this many times. I still don’t understand the reason why this tiny amount of code hasn’t been added and people keep recommended the far more complex solution.

Seems like programmers pride to me but what do I know.

Offline

#10 2009-03-10 20:15:38

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

Re: Come on, make if_data core

Els wrote:

BTW, I’d think that chh_if_data has to do something similar to calling an article tag to check if there is content, right?

Correct. As far as I recall (wet put me straight last time I asked about adding this functionality to the core), it parses the tag twice; once to evaluate if it has input and once to actually do it, if it does have data. Thus your tip about setting limit="1" in the test is a very prudent processor-saving method :-)

The great thing about the variable approach, as you say, is that they don’t have to just check for data/no data. ISTR some of your devious examples in other posts check the number of file downloads in a particular category and take action (or something). In a recent site I’ve used a shedload of variables to store a mini database of content in a single form. I include that form on a page and then display stuff from the data store if_variable matches some given input or if_variable exists.

txp:variables really are fabulous and the reason I’ve pretty much stopped using chh_if_data now.


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

#11 2009-03-10 20:42:01

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Come on, make if_data core

Fair enough. I’ll start using if_variable no problem.

It does seem like adding an if_article_image is awfully specific, and somehwat silly. A simple if_data would neatly kill a whole flock of birds with the same stone including if_article_image.

It kinda opens the door to all kinds of silliness; if_body, if_sitename, if_filename, if_donkeys_sit_on_my_head, if_I_were_a_rich_man

I’m all for elegance, not tag creep.

Last edited by mrdale (2009-03-10 20:42:59)

Offline

#12 2009-03-10 21:04:07

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

Re: Come on, make if_data core

mrdale wrote:

It does seem like adding an if_article_image is awfully specific

Yes, curious. Especially since Els’ construct above works here too, albeit less elegantly than a dedicated tag. I dunno, fine line between hundreds of tags with one function each, and one tag to rule them all…


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

Board footer

Powered by FluxBB