Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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
Re: experimenting with the evaluate tag
@jakob well, but then variable
is named aimg
but tested as custom_field_name
too :-)
Offline
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
Offline
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
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
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
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