Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#49 2016-11-07 14:51:34

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

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

#50 2016-11-07 15:22:01

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#51 2016-11-07 16:57:36

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

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

#52 2016-11-08 12:03:23

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

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

#53 2016-11-08 13:24:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

Offline

#54 2016-11-08 15:37:03

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

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 using evil() 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

#55 2016-11-09 11:40:32

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

Re: Textpattern evaluation (dis)abilities

Bloke wrote #302760:

If this hits core…

and if <txp:if query="2*2" /> outputting 4 is comprehensible, one could probably follow Adi and rename <txp:evaluate /> to <txp:if />. A poll?

Offline

#56 2016-11-09 11:51:22

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

Re: Textpattern evaluation (dis)abilities

etc wrote #302797:

and if <txp:if query="2*2" /> outputting 4 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

#57 2016-11-10 09:10:12

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

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


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

Offline

#58 2017-07-24 15:11:08

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#59 2017-07-24 15:54:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

Offline

#60 2017-07-24 15:58:39

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Textpattern evaluation (dis)abilities

Bloke wrote #306418:

Sure…

Tested, perfect, thanks!

Offline

Board footer

Powered by FluxBB