Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2016-10-27 11:30:20

etc
Developer
Registered: 2010-11-11
Posts: 3,859
Website

Re: Textpattern evaluation (dis)abilities

NicolasGraph wrote #302514:

Just a word about that; on my side I’d prefer to keep txp: for tags and use something else for attributes; underscore seems ok to me, and it is three characters less! ;-)

+1

Offline

#12 2016-10-27 11:42:15

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

Re: Textpattern evaluation (dis)abilities

etc wrote #302513:

Here I must disagree: how <txp:evaluate query="2*2=4" /> is less readable than

<txp:adi_calc name="test" value="2" multiply="2" />...

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.

If txp:evaluate is to become a general purpose conditional maybe it should be txp:if.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 3,859
Website

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: 975
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: 3,859
Website

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: 2,111
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 ?

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 3,859
Website

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: 2,111
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 ?

Offline

Board footer

Powered by FluxBB