Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-11-07 17:17:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

experimenting with the evaluate tag

I’m experimenting with the txp:evaluate tag so as to get rid of my now outdated txp:variable ones.

In a simplified manner, where I had:

<txp:variable name="aimg" value='<txp:custom_field name="custom_field_name" />' />
<txp:if_variable name="custom_field_name" value="">
<p>Nothing here.</p>
<txp:else />
<txp:variable name="custom_field_name" />
</txp:if_variable>

Am I assuming correctly that it could be replaced with:

<txp:evaluate test="custom_field_name">
<txp:custom_field name="custom_field_name" />
<txp:else />
<p>Nothing here.</p>
</txp:evaluate>

and… is the evaluate use more memory efficient? Does it have fewer db queries?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2018-11-07 17:28:09

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

Re: experimenting with the evaluate tag

In this case the most straightforward is

<txp:if_custom_field name="custom_field_name">
    <txp:custom_field name="custom_field_name" />
<txp:else />
    <p>Nothing here.</p>
</txp:if_custom_field>

In general, the more targeted the better.

Offline

#3 2018-11-07 17:33:27

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: experimenting with the evaluate tag

Hi Oleg… That was quick!!

I’m aware of the if_custom_field tag… Your answer was however, very good to know. Maybe it was the wrong example. I was also thinking if the usage principle for the evaluate tag was correct.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2018-11-07 21:24:07

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

Re: experimenting with the evaluate tag

colak wrote #315053:

Hi Oleg… That was quick!!

I was in a rush :-) Well, I don’t think there is a noticeable difference between your variable and evaluate solutions, unless the custom field is megabytes long. In this (highly improbable) case evaluate might be better, because it does not store its content in memory once processed, unlike variable.

A basic usage example for evaluate could be the following:

<txp:evaluate test="older, newer" wraptag="nav">
    <txp:older wraptag="span">Older</txp:older>
    <span>Page <txp:page_url type="pg" /></span>
    <txp:newer wraptag="span">Newer</txp:newer>
</txp:evaluate>

This nav block will be output only if there are other pages (there is no sense to output Page 1 otherwise). Try to do it with variable, I don’t think the solution will be as elegant.

Other cases involve query attribute, but it had no equivalent in 4.6.

Offline

#5 2018-11-07 21:52:01

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: experimenting with the evaluate tag

colak wrote #315053:

I was also thinking if the usage principle for the evaluate tag was correct.

Going back to your first example, I think you had a minor syntax mistake in there. The test attribute has to be one or more txp:tags, so instead of <txp:evaluate test="custom_field_name"> (which is the attribute), it should just be test="custom_field" (which is the tag):

<txp:evaluate test="custom_field"> 
    Show <txp:custom_field name="…" /> with text before and after.
</txp:evaluate>

TXP Builders – finely-crafted code, design and txp

Offline

#6 2018-11-07 21:54:27

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

Re: experimenting with the evaluate tag

@jakob well, but then variable is named aimg but tested as custom_field_name too :-)

Offline

#7 2018-11-07 21:58:19

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: experimenting with the evaluate tag

You’re right, that’s not needed either, but I suspect Yiannis was simplifying more complex code and there may have been a reason for that. My point was – and correct me if I’m wrong – that test has to be a txp:tag name.


TXP Builders – finely-crafted code, design and txp

Offline

#8 2018-11-07 22:09:15

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

Re: experimenting with the evaluate tag

jakob wrote #315066:

My point was – and correct me if I’m wrong – that test has to be a txp:tag name.

Absolutely, or a list of tag names. But I suppose Yiannis has just copied the (equally not working) variable block.

Offline

#9 2018-11-08 06:27:51

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: experimenting with the evaluate tag

well, the code online is working but on simplifying it, I made it invalid. In any case it is this kind of discussion I was looking for. The evaluate tag seems very powerful but also, maybe because of its flexibility, it is not as easy to understand in the real txp world.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#10 2018-11-08 10:37:08

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

Re: experimenting with the evaluate tag

The workflow of test is quite simple: these tags are processed first, and, if some of them output something, the rest of the block is processed and the block is output. Otherwise the parsed else part (if given) is output.

Offline

#11 2018-11-08 12:16:42

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: experimenting with the evaluate tag

I guess my confusion lied and solved by what Julian wrote.

I actually thought that we could directly target a field with the tag but… I got the test attribute now.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#12 2018-11-08 20:58:11

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

Re: experimenting with the evaluate tag

colak wrote #315081:

I actually thought that we could directly target a field with the tag

Wouldn’t that just make it <txp:if_custom_field /> clone? Or are you thinking of multiple cf testing? Then we could amend <txp:if_custom_field /> in this sense.

Offline

Board footer

Powered by FluxBB