Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Textpattern evaluation (dis)abilities
gomedia wrote #302517:
Poor little adi_calc – it’s only a simple little sausage! To me that says very loudly: perform a calculation on a variable and then test the value of the variable.
And how you’d write (2+3)*4-5 > 6? adi_calc is very practical for variable assignments/transforms, but less tags — faster parsing. And if you register few well-named functions to use with <txp:evaluate />, you’ll be able to evaluate something like <txp:evaluate query="day('now') = 'Friday'" />.
If
txp:evaluateis to become a general purpose conditional maybe it should betxp:if.
It’s not only conditional, <txp:evaluate query="(2+3)*4-5" /> will output 15.
Offline
Re: Textpattern evaluation (dis)abilities
I like the proposal, though I don’t have time to test it out at the moment. I find the examples pretty easy to understand.
Offline
Re: Textpattern evaluation (dis)abilities
gomedia wrote #302512:
I think adi_if_content (written by etc) is a better & more powerful candidate for core inclusion.
FYI, done, thanks for the idea.
Offline
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