Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2016-11-06 11:58:28

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: Textpattern evaluation (dis)abilities

Should we rename test to ifempty?

Offline

#32 2016-11-06 12:07:55

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,656
Website

Re: Textpattern evaluation (dis)abilities

Maybe? It is more obvious what it does.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg

Offline

#33 2016-11-06 14:29:07

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Textpattern evaluation (dis)abilities

etc wrote #302693:

Should we rename test to ifempty?

I don’t know; the hard thing is that Txp usually manage conditonal content on a tag basic, where if and else are on the same “level”:

<txp:if…>
    Yes
<txp:else />
    No
</txp:if…>

<txp:hide ifempty> is a bit different than what we used to do in mind. I understand the idea to improve an existing tag instead of adding another conditional one but doesn’t it break the above logic? I don’t want to disturb you in your precious work on Txp Oleg; but here are my thoughts for now.

Edited for clarity.

Last edited by NicolasGraph (2016-11-06 16:02:05)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#34 2016-11-06 15:08:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,471
Website GitHub

Re: Textpattern evaluation (dis)abilities

etc wrote #302693:

Should we rename test to ifempty?

In the same vein as what NicholasGraph says, normally I’m not a fan of negative logic. Hiding something if it’s empty is the same as showing it if it isn’t. But since the tag ‘hide’ is already “negative” there’s probably not much else we can do about it, so:

<txp:hide ifempty>
	<h1>Here's an article list</h1>
	<txp:article />
<txp:else />
	Nothing to say today
</txp:hide>

is as good as anything, I guess. The ‘else’ part just seems a bit, I dunno, difficult to follow. It could be taken to mean:

Hide this if such-and-such is empty else show that if such_and_such has content.

In reality, it’s:

Hide this if such-and-such is empty and show that instead, but show this if such_and_such has content.

Not ideal logic, but I can’t think of anything better.

Presumably, if there’s more than one tag in the container and you only cared about the result of one tag, you’d then specify which of the tags you wanted to test for emptiness in the ifempty attribute? Otherwise, would it check if all of them were empty?

Last edited by Bloke (2016-11-06 15:20:31)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#35 2016-11-06 17:55:57

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: Textpattern evaluation (dis)abilities

Bloke wrote #302699:

Presumably, if there’s more than one tag in the container and you only cared about the result of one tag, you’d then specify which of the tags you wanted to test for emptiness in the ifempty attribute? Otherwise, would it check if all of them were empty?

If you pass ifempty="tag1,tag2" to <txp:hide />, it will

  • process all found <txp:tag1 /> and <txp:tag2 />;
  • only if (at least) one of them is not empty, process other tags and display the result;
  • otherwise, output the else part, if any, without even processing other tags.

If you additionally pass it process="tag3,tag4" attribute, it will process <txp:tag3 /> and <txp:tag4 /> too, but they wont be checked for emptiness.

Offline

#36 2016-11-06 18:15:20

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

Re: Textpattern evaluation (dis)abilities

Bloke wrote #302699:

I’m not a fan of negative logic.

What if it was made more grammatically correct:

<txp:hide ifdata="tag1,tag2">
<h1>Here's an article list</h1>
<txp:article />
<txp:else />
<!-- Nothing -->
</txp:hide>

Also if we are to reduce tags this could be made to work too.

<txp:hide ifdata="tag1,tag2">
<h1>Here's an article list</h1>
<txp:article />
</txp:hide>

Which parses nothing, if no data is present in tag1 or tag2.

>Edited to add: the problem with the above, whole sites might be built using the negative logic above.

Once we get rid of some of the if_ tags many site templates could be enclosed in <txp:hide /> tags which would be very strange, especially to the uninitiated.

Last edited by colak (2016-11-06 18:26:56)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#37 2016-11-06 19:57:25

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: Textpattern evaluation (dis)abilities

It’s pity to introduce a new tag that is just “opposite” of an existing one, but I have to admit that

<txp:show ifdata>...<txp:else />...</txp:show>

looks more natural than its hide equivalent. But then <txp:show>...</txp:show> (without attributes) sounds strange.

Offline

#38 2016-11-06 20:44:58

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Textpattern evaluation (dis)abilities

One of the beauties of Textpattern is code readability and whilst I can see a functional connection with txp:hide, I’d prefer something more self-explanatory such as <txp:show ifdata> or even <txp:if_data>.

Offline

#39 2016-11-06 20:51:53

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Textpattern evaluation (dis)abilities

etc wrote #302706:

[…] But then <txp:show>...</txp:show> (without attributes) sounds strange.

Yes if we would introduce a new tag I would think about something clother to adi_if_content. <txp:if_content> or <txp:if_data> would follow the usual Txp conditionning way.

Last edited by NicolasGraph (2016-11-06 21:27:54)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#40 2016-11-06 21:00:42

jpdupont
Member
Registered: 2004-10-01
Posts: 752

Re: Textpattern evaluation (dis)abilities

gomedia,
etc : +1. <txp:show /> seems more natural, logic.

Offline

#41 2016-11-07 05:50:40

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

Re: Textpattern evaluation (dis)abilities

gomedia wrote #302709:

One of the beauties of Textpattern is code readability

I guess that I agree with Adi. What about:

<txp:hide unless="tag1,tag2">
<h1>Here's an article list</h1>
<txp:article />
<txp:else />
<!-- Nothing -->
</txp:hide>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#42 2016-11-07 09:14:10

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Textpattern evaluation (dis)abilities

colak wrote #302721:

I guess that I agree with Adi. What about:

<txp:hide unless="tag1,tag2">...

I like the unless attribute but wouldn’t it start to be confusing when <txp:else /> is needed (hide unless, else…). Too much “alternative” things for my brain. ;/

Last edited by NicolasGraph (2016-11-07 09:15:03)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#43 2016-11-07 10:12:46

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

Re: Textpattern evaluation (dis)abilities

I guess the big question here is whether we should upgrade the txp:hide tag that much.

For now it is mostly used

  • for not executing txp or other code we might not want to delete just yet
  • Insert comments which we might not want them to be visible in the source of the front end.

I understand Oleg’s logic to reduce the tags but to achieve that, we may need to invent another one. A swiss army knife of tags which could be readily used in all contexts, as well as it being easily readable to non programmers.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#44 2016-11-07 11:53:07

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: Textpattern evaluation (dis)abilities

NicolasGraph wrote #302728:

Too much “alternative” things for my brain. ;/

colak wrote #302738:

I guess the big question here is whether we should upgrade the txp:hide tag that much.

Yep, it looks to much for <txp:hide />. I guess, we still can give it process attribute (to say process but hide) and, maybe, enhance it in some other way? But unless we drop the else part (or drop the idea completely), a new name seems to be the only readable solution.

Offline

#45 2016-11-07 12:06:53

etc
Developer
Registered: 2010-11-11
Posts: 5,681
Website GitHub

Re: Textpattern evaluation (dis)abilities

Which makes me wonder if <txp:evaluate /> could fit?

<txp:evaluate query="2*2=4" />

<txp:evaluate test="article">
    <txp:newer /><txp:older />
    <txp:article />
<txp:else />
    Nothing new
</txp:evaluate>

At least, it would give this threads title some sense :-)

Offline

Board footer

Powered by FluxBB