Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-22 13:48:16

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

multiple values for attribute "value" in <txp:if_variable>

With a serious dalay I’m now working on a new site using txp 4.07 and I must say it is really impressive, a great step ahead.
Anyway I have a request, even if I realize it probably will not be taken into consideration for upcoming version 4.08: will it be possible to use multiple values for attribute “value” in <txp:if_variable>? I would find it very useful.

P.S. thanks again to all developers for their great work

Last edited by redbot (2009-01-22 13:49:45)

Offline

#2 2009-01-22 14:16:02

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: multiple values for attribute "value" in <txp:if_variable>

A list of values would have to be separated by a special character, presumably a comma, which would then have to be excluded (or escaped) from the individual values.

E.g.:

<txp:if_variable name="foo" value="apple,pear,orange">

tests for either “apple”, “pear”, or “orange”, while

<txp:if_variable name="foo" value="oh\,my,dear,darling">

tests for either “oh,my”, “dear”, or “darling”

Is this a feasible solution?

Offline

#3 2009-01-22 14:36:19

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: multiple values for attribute "value" in <txp:if_variable>

Wet you’re right, I hadn’t thought about this.
I like your solution, maybe another one could be to wrap in “’” the values containing a comma, like this:

<txp:if_variable name="foo" value="'oh,my',dear,darling">

anyway I’d be happy with both solutions. Thank you!

Offline

#4 2009-01-22 18:33:28

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: multiple values for attribute "value" in <txp:if_variable>

I’d limit functionality to a simple comma separated list, similar to all other TXP tags that allow comma separated values:

<txp:if_variable name="foo" value="apple,pear,orange">

Offline

#5 2009-01-22 18:43:37

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: multiple values for attribute "value" in <txp:if_variable>

ruud wrote:

I’d limit functionality to a simple comma separated list, similar to all other TXP tags that allow comma separated values:

Yes ruud, this was my initial request, but then there is the problem outlined by wet (if txp:variable has a value which contains a comma).

Offline

#6 2009-01-22 19:20:38

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: multiple values for attribute "value" in <txp:if_variable>

I suspect in most cases one could use different values instead to avoid that problem. Introducing a new escaping method for this purpose is not worth it. Tag functionality is always limited in some way, so this would be a limitation of this particular tag, IMHO. Keep it simple!

Offline

#7 2009-01-23 01:49:29

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: multiple values for attribute "value" in <txp:if_variable>

Mmm… yes, from my point of view your solution is ok too.
And actually I have no idea how many people are using the <txp:if_variable> and <txp:variable> tags in ‘creative’ ways, so probably you are right when you say it’s not worth the effort.
Well… I realize I can’t add nothing particularly brilliant to the discussion now so I’ll stop talking.
Thank you again

Offline

#8 2009-01-23 10:41:32

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: multiple values for attribute "value" in <txp:if_variable>

You could always add a second attribute, say values?

Offline

#9 2009-08-25 20:10:48

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

Re: multiple values for attribute "value" in <txp:if_variable>

Did this make it into v4.2?

If not, can you do an Indiana Jones and reach back and grab your hat (tag) before the stone rolls shut ;-) ?

(found wet’s suggestion most consistent with other tags)

Last edited by jakob (2009-08-25 20:12:08)


TXP Builders – finely-crafted code, design and txp

Offline

#10 2010-10-14 22:58:43

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: multiple values for attribute "value" in <txp:if_variable>

I found this old thread by chance and now I’m wondering if there is a slight possibility this will be included in txp 4.3 (yes I know it’s late).
I can’t have a look at the code but maybe something could be borrowed from the recent changes in “if_custom_field” tag?

Offline

#11 2011-03-23 16:05:09

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: multiple values for attribute "value" in <txp:if_variable>

ruud wrote:

I’d limit functionality to a simple comma separated list, similar to all other TXP tags that allow comma separated values:

<txp:if_variable name="foo" value="apple,pear,orange">

What’s the current way to do this? Is there any native way? Is smd_if the only option? Is there some other method?

Thank you!

[Edit: Fix bq formating.]

Last edited by johnstephens (2011-03-23 16:05:47)

Offline

#12 2011-03-23 21:29:11

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: multiple values for attribute "value" in <txp:if_variable>

If you don’t need to test against too many values, you can nest the if_variable tags:

<txp:if_variable name="foo" value="apple">
   OK
<txp:else />
   <txp:if_variable name="foo" value="orange">
      OK
   <txp:else />
      <txp:if_variable name="foo" value="pear">
         OK
      <txp:else />
         Not OK
      </txp:if_variable>
   </txp:if_variable>
</txp:if_variable>

Offline

Board footer

Powered by FluxBB