Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Textpattern evaluation (dis)abilities
phiw13 wrote #302743:
Make that 3.
Great! Would be ideal for a bottle of vodka ;-)
But adding the
<txp:else />
in the mix becomes very strange and confusing.
Agreed, that’s because I’d rather delegate this functionality to <txp:evaluate />
.
As for the
<txp:evaluate />
, hmm, maybe? How is actually different from playing around with<txp:variable />
? Readability?
Not only. With variable
you can test only for equality: <txp:if_variable name="test" value="5" />
. With <txp:evaluate />
you could do more:
<txp:evaluate query='<txp:variable name="test" /> > 2' />
<txp:evaluate query='<txp:variable name="test" /> mod 3 = 2' />
<txp:evaluate query='ceiling(<txp:variable name="test" /> div 3) = 2' />
and other conditions.
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302744:
Not only. With
variable
you can test only for equality:<txp:if_variable name="test" value="5" />
. With<txp:evaluate />
you could do more:
So
<txp:if_variable name="test" value="5" >
and
<txp:evaluate query='<txp:variable name="test" > = 5' />
would do the same thing?
I would definitely love to see some version of
<txp:smd_if field="txpvar:test" operator="isused">
Perhaps
<txp:evaluate query='<txp:variable name="test" /> = NULL' >
Also, This makes <txp:if_variable />
redundant. Which is okay.
Offline
Re: Textpattern evaluation (dis)abilities
michaelkpate wrote #302745:
So
<txp:if_variable name="test" value="5" />
and
<txp:evaluate query='<txp:variable name="test" /> = 5' />
would do the same thing?
If <txp:variable name="test" />
is set, yes. Otherwise, the former will return an empty string, while the later will issue an error.
I would definitely love to see some version of
<txp:smd_if field="txpvar:test" operator="isused">
<txp:evaluate />
(as I see it) can not do this, but, if I get it right, <txp:if_variable name="test" />
already does what you need.
Also, This makes
<txp:if_variable />
redundant. Which is okay.
This tag is so widely used that I doubt we could deprecate it in a near future. The purpose of <txp:evaluate />
is rather to provide a “safe” version of <txp:php />
, available to non-admin users as well.
Offline
Re: Textpattern evaluation (dis)abilities
Anyone willing can test new <txp:hide />
and <txp:evaluate />
tags in this branch.
<txp:hide />
hides its content, as before, but can (selectively) process it if passed process
attribute. <txp:evaluate />
accepts query
and test
attributes and works like this:
<!-- outputs 4 -->
<txp:evaluate query="2*2" />
<!-- outputs the block if article is not empty -->
<txp:evaluate test="article">
<txp:newer /><txp:older />
<txp:article />
<txp:else />
<txp:link_to_home />
</txp:evaluate>
<!-- outputs the block if 2*2=4 and article is not empty -->
<txp:evaluate query="2*2=4" test="article">
<txp:newer /><txp:older />
<txp:article />
<txp:else />
<txp:link_to_home />
</txp:evaluate>
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302758:
Anyone willing can test new
<txp:hide />
and<txp:evaluate />
tags
I’ll clone and test it later, thank you. If this hits core, I wonder if I could rewrite smd_if using <txp:evaluate>
instead of building tests up by hand and using evil() eval()
to check the results. Hmmm…
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Textpattern evaluation (dis)abilities
Bloke wrote #302760:
I wonder if I could rewrite smd_if using
<txp:evaluate>
instead of building tests up by hand and usingevil()eval()
to check the results. Hmmm…
I don’t think you can rewrite everything (like isused
) effortlessly, but it could be possible. You’d need to define few string functions (like isused()
and field()
) and append them to $prefs['txp_functions']
(currently empty). You would then be able to call (internally or in a form) something like
<txp:evaluate query="isused('variable', 'my_var') and not(starts-with(field('variable', 'my_name'), 'smd'))">
yep
<txp:else />
nope
</txp:evaluate>
But I’m not sure these queries are any easier to build from smd_if
attributes.
Last edited by etc (2016-11-09 11:35:44)
Offline
Offline
Re: Textpattern evaluation (dis)abilities
etc wrote #302797:
and if
<txp:if query="2*2" />
outputting4
is comprehensible, one could probably follow Adi and rename<txp:evaluate />
to<txp:if />
. A poll?
Dunno- I think <txp:evaluate />
is more readable & understandable. On the flip side, a few more characters to type, but I don’t consider that a problem, personally.
(haven’t tested your branch yet, busy with real world things…)
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Textpattern evaluation (dis)abilities
phiw13 wrote #302798:
Dunno- I think
<txp:evaluate />
is more readable & understandable. On the flip side, a few more characters to type, but I don’t consider that a problem, personally.(haven’t tested your branch yet, busy with real world things…)
+1
Offline
Re: Textpattern evaluation (dis)abilities
Hi,
Can I use this tag to get the pixel value of <txp:image_info type="w" />
and then output that value divided by 2?
So, basically, if my double pixel 2x
image is 2048
pixels wide, I want the output to be 1024
.
Offline
Re: Textpattern evaluation (dis)abilities
philwareham wrote #306416:
Can I use this tag to get the pixel value of
<txp:image_info type="w" />
and then output that value divided by 2?
Sure:
<txp:evaluate query='<txp:image_info type="w" />div2' />
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Textpattern evaluation (dis)abilities
Offline