Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2016-11-04 21:54:08

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

Re: Textpattern evaluation (dis)abilities

This has nothing to do with the OP, but since <txp:hide /> discussion has started here, let’s continue. I’m about to merge what is suggested by Nicolas, just wanted to check if it’s ok.

New <txp:hide /> will accept test and process attributes and work like this:

<!-- neither process nor output, as before -->
<txp:hide>content</txp:hide>
<!-- firstly checks if there are some articles, then parses newer/older and outputs the block -->
<txp:hide test="article">
    <txp:newer /><txp:older />
    <txp:article />
</txp:hide>
<!-- processes variable, checks if there are some articles, then parses newer/older -->
<txp:hide test="article" process="variable">
    <txp:variable name="limit" value="5" />
    <h3>Articles paged by <txp:variable name="limit" /></h3>
    <txp:newer /><txp:older />
    <txp:article limit='<txp:variable name="limit" />' />
</txp:hide>
<!-- processes the code and sets variables, but hides the block from visitors -->
<txp:hide process>
    <!-- some comment for devs -->
    <txp:variable name="param1" value="1" />
    <!-- another comment for devs -->
    <txp:variable name="param2" value="2" />
</txp:hide>

All comments are welcome.

Last edited by etc (2016-11-05 10:43:00)

Offline

#26 2016-11-05 08:29:37

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

Re: Textpattern evaluation (dis)abilities

Think I’m starting to grasp this conceptually now. This sounds ace.


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

#27 2016-11-05 10:36:55

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

Re: Textpattern evaluation (dis)abilities

Bloke wrote #302672:

Think I’m starting to grasp this conceptually now.

Sure you do, it’s all about conditional processing/output. I’m not quite satisfied with attribute names (test and process), but can not find any better.

Offline

#28 2016-11-05 20:02:05

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

Re: Textpattern evaluation (dis)abilities

In adi_if_content it’s not necessary to explicitly specify the tag to be tested, e.g.:

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

What would be the equivalent in the new txp:hide?

Offline

#29 2016-11-05 23:30:50

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

Re: Textpattern evaluation (dis)abilities

gomedia wrote #302684:

What would be the equivalent in the new txp:hide?

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

Offline

#30 2016-11-06 09:32:30

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

Re: Textpattern evaluation (dis)abilities

Hi, I’m just wondering… “semantically” should it be:

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

or

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

With adi_if_content it was logical to have to have the tested content in the first part of the code (adi_if_content means display if) but as we would now use hide, shouldn’t the tested content be in the else part (hide, else display…)?

Edited fo clarity.

Last edited by NicolasGraph (2016-11-06 11:55:39)


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

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,257
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: Japan
Registered: 2004-02-27
Posts: 3,249
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

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: 11,480
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.

Txp Builders – finely-crafted code, design and Txp

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,257
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,101
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

Board footer

Powered by FluxBB