Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302549:
FYI, done, thanks for the idea.
Can you give an example / usage for the ignore and insert attributes ? I think I get the <txp:hide test /> one. Obviously need to play a little more to find good ways to use it.
Thanks.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Textpattern evaluation (dis)abilities
phiw13 wrote #302586:
Can you give an example / usage for the
ignoreandinsertattributes ?
Sure. Suppose that you want to display newer/older links above the article list. To be populated, they need <txp:article /> to be called first. Previously you had to do this
<txp:article pgonly="1" />
<txp:newer><txp:text item="newer" /></txp:newer>
<txp:older><txp:text item="older" /></txp:older>
<txp:text item="recent_articles" />
<txp:article />
or better, but less readable
<txp:variable name="articles" value='<txp:article />' />
<txp:newer><txp:text item="newer" /></txp:newer>
<txp:older><txp:text item="older" /></txp:older>
<txp:if_variable name="articles" value=""><txp:else />
<txp:text item="recent_articles" />
<txp:variable name="articles" />
<txp:if_variable>
Now you can also use <txp:hide />, inserting (i.e. processing) the links after <txp:article /> is processed (and is not empty). And since <txp:text /> always outputs something, we ignore it when checking for emptiness:
<txp:hide insert="newer, older" ignore="text">
<txp:newer><txp:text item="newer" /></txp:newer>
<txp:older><txp:text item="older" /></txp:older>
<txp:text item="recent_articles" />
<txp:article />
</txp:hide>
If <txp:article /> is empty, nothing will be output (even not <txp:text item="recent_articles" />). We could also test only article, to the same effect:
<txp:hide insert="newer, older" test="article">
<txp:newer><txp:text item="newer" /></txp:newer>
<txp:older><txp:text item="older" /></txp:older>
<txp:text item="recent_articles" />
<txp:article />
</txp:hide>
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302593:
We could also test only
article, to the same effect…
That is probably why it is not obvious to understand why test wouldn’t be enough. Is there something you can do with insert that you couldn’t with test?
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302593:
Sure. […]
Thanks! I think I get it now. Now, to take some time and play with all my snippets.
I like the sound of this.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Textpattern evaluation (dis)abilities
NicolasGraph wrote #302596:
That is probably why it is not obvious to understand why
testwouldn’t be enough. Is there something you can do withinsertthat you couldn’t withtest?
This will not work, because <txp:newer/older /> will be processed before <txp:article />, when the necessary pagination data is not yet set:
<txp:hide test="article">
<txp:newer><txp:text item="newer" /></txp:newer>
<txp:older><txp:text item="older" /></txp:older>
<txp:text item="recent_articles" />
<txp:article />
</txp:hide>
We could say “test first, then insert all the rest” by default, but then this would not work (or we’ll have to add variable to test or ignore):
<txp:hide test="article">
<txp:variable name="limit" value="5" />
<txp:article limit='<txp:variable name="limit" />' />
</txp:hide>
I’m not sure which way is more intuitive, open to all suggestions.
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302601:
We could say “test first, then insert all the rest” by default…
+1
…but then this would not work (or we’ll have to add
variabletotestorignore).
I would probably use ignore="variable".
Edited for clarity.
Last edited by NicolasGraph (2016-11-03 09:39:07)
Offline
Re: Textpattern evaluation (dis)abilities
If we remove insert and say “test first, then insert all the rest”, I’d see something like:
<txp:hide test="article" do="variable">
<txp:variable name="limit" value="5" />
<txp:article limit='<txp:variable name="limit" />' />
</txp:hide>
The ignore attribute would be renamed do.
Last edited by NicolasGraph (2016-11-03 10:01:21)
Offline
Re: Textpattern evaluation (dis)abilities
NicolasGraph wrote #302603:
If we remove
insertand say “test first, then insert all the rest”, I’d see something like:
<txp:hide test="article" do="variable">...The
ignoreattribute would be renameddo.
Yes, maybe. Or process? I will think of it.
Offline
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.
Hire 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