Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
Offline
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)
Offline
Offline
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
Re: Textpattern evaluation (dis)abilities
etc wrote #302693:
Should we rename
test
toifempty
?
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)
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302693:
Should we rename
test
toifempty
?
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
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
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