Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2016-10-27 11:56:40

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

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:evaluate is to become a general purpose conditional maybe it should be txp:if.

It’s not only conditional, <txp:evaluate query="(2+3)*4-5" /> will output 15.

Offline

#14 2016-10-27 14:40:49

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 976
Website

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

#15 2016-11-02 12:07:10

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

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

#16 2016-11-02 13:06:26

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

Re: Textpattern evaluation (dis)abilities

etc wrote #302549:

FYI, done, thanks for the idea.

I don’t use to play with txp:hide, but I will; nice enhancement!


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

Offline

#17 2016-11-03 05:36:08

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,165
Website

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

Offline

#18 2016-11-03 08:58:56

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

Re: Textpattern evaluation (dis)abilities

phiw13 wrote #302586:

Can you give an example / usage for the ignore and insert attributes ?

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

#19 2016-11-03 09:09:26

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

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?


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

Offline

#20 2016-11-03 09:13:01

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,165
Website

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

Offline

#21 2016-11-03 09:24:49

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

Re: Textpattern evaluation (dis)abilities

NicolasGraph wrote #302596:

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?

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

#22 2016-11-03 09:35:07

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

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 variable to test or ignore).

I would probably use ignore="variable".

Edited for clarity.

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


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

Offline

#23 2016-11-03 09:59:29

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

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)


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

Offline

#24 2016-11-03 10:07:55

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

Re: Textpattern evaluation (dis)abilities

NicolasGraph wrote #302603:

If we remove insert and say “test first, then insert all the rest”, I’d see something like:

<txp:hide test="article" do="variable">...

The ignore attribute would be renamed do.

Yes, maybe. Or process? I will think of it.

Offline

Board footer

Powered by FluxBB