Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#211 2009-02-25 16:16:40

hamato
New Member
Registered: 2009-02-21
Posts: 9

Re: smd_if: Generic multiple if condition tests

No difference. :( That trick does work, but sort='FIELD(ID,<txp:variable name="ids" />)' and sort="custom_9 asc" are giving same results (as expected when I think about it). The moment I add a sort attribute to article_customlimit and offset gets broken. Or at least, they are not working as I would want. I don’t know why exactly.

Thanks anyway for trying to help me. Much appreciated. I’m feeling bad for spamming this thread about stuff that is not that much related to smd_if…. or it is? Maybe I should start a new topic in “How Do I…? & Other Questions” section. (edit: and I did… )

Sometimes simple thing make you spend hours and hours working. :(

Last edited by hamato (2009-02-25 19:41:33)

Offline

#212 2009-03-20 17:56:56

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_if: Generic multiple if condition tests

Hi,

This is probably a stupid question, but here it is:

How do I access $_POST[ ] variables?
I can access $_GET[ ] variables with urlvar:var_name, but what about post variables?

Thanks,
Kostas

Offline

#213 2009-03-20 19:43:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests

kostas45 wrote:

How do I access $_POST[ ] variables?

Not a stupid question at all because the plugin, ahem *cough* can’t access them. It’s a ridiculous oversight on my part and I can’t believe it’s taken over a year for someone to notice! Thanks for spotting it.

For the vageuly interested I started out using TXP’s built-in gps() function which grabs either POST or GET, but if neither exist it sets an empty value (the ‘s’ of gps). When trying to testi if a value has been used (at all) this is no good, so I ripped out the gps() calls and replaced them with (albeit unsafe) $_GET calls. And promptly forgot to add $_POST as well. D’oh!

I’ll have it fixed in no time. Here is some hold music…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#214 2009-03-20 20:36:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#215 2009-03-21 09:25:19

kostas45
Member
From: Greece
Registered: 2007-11-08
Posts: 61

Re: smd_if: Generic multiple if condition tests

Excellent, works like a charm!
Thanks a lot Stef :-)

Cheers,
Kostas

Offline

#216 2009-03-22 11:10:14

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: smd_if: Generic multiple if condition tests

Hi Stef,

Having great time with your indispensable smd_if, thanks.

Now that we’re all doing lovely tags within tags, there’s an increased danger of whitespace creeping in where you don’t expect it. This might lead to problems, for example:

<txp:variable name="x" value=" 9 " />
<txp:variable name="y" value="1" />
<txp:smd_if field="txpvar:x" operator="lt" value="txpvar:y">
<txp:variable name="x"/> is less than <txp:variable name="y"/>
</txp:smd_if>

Note the spaces around the x variable’s value. This interferes with the “less than” comparison & things go awry. Is this something that smd_if could cater for or do we just need to be very careful?

Cheers,

Adi

Offline

#217 2009-03-22 19:50:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests

gomedia wrote:

Now that we’re all doing lovely tags within tags, there’s an increased danger of whitespace creeping in where you don’t expect it.

Glad you’re finding the plugin useful. There’s a kind of undocumented solution to the spaces thing (err, I think). If you are expecting a value (or a field) that may have spaces in it, add :NOTAGS to the variable (e.g. txpvar:x:NOTAGS). That strips out PHP and HTML tags from the string and also performs a trim() to remove whitespace (because often simply removing tags leaves extraneous whitespace lying around).

If it helps any — and you can perhaps see a situation when you may need to trim extraneous spaces without stripping PHP/HTML tags — I could add a dedicated TRIM modifier to the next version? Currently, the NOSPACE modifier could be (mis)used if you like, but since it only works on fields you’d have to switch your value/field attributes over which may or may not yield the desired true/false result from the plugin.

Let me know if you think a TRIM modifier would help (and any other modifiers you might consider useful — I could add them all at once).

Last edited by Bloke (2009-03-22 19:50:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#218 2009-03-22 20:57:00

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: smd_if: Generic multiple if condition tests

Bloke wrote:

Let me know if you think a TRIM modifier would help …

Thanks Stef, I think it would be a useful safety harness. And it would mean that we could keep some semblance of readability in the source code – so instead of:

<txp:variable name="height" value='<txp:upm_article_image><txp:upm_img_full_height /></txp:upm_article_image>' />

We could do:

<txp:variable name="height" value='
  <txp:upm_article_image>
    <txp:upm_img_full_height />
  </txp:upm_article_image>
'/>

and not have to worry about blanks/tabs/newlines etc.

Cheers,

Adi

Offline

#219 2009-03-22 21:28:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#220 2009-03-22 21:47:53

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: smd_if: Generic multiple if condition tests

Stef,

Blimey, you’re quick off the mark. Thanks.

Too quick for me! I’d just sat down to send you another suggestion: a trim="1" attribute, to save having to use a modifier in both field & value.

All the best,

Adi

Offline

#221 2009-03-22 22:37:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests

gomedia wrote:

a trim="1" attribute

I didn’t do it that way in case you only wanted to apply it to one particular test — it’s more granular when comparing multiple, disparate things. But offering the option to globally apply it makes sense so I’ll do that as well to save you the hassle if you need to trim all fields+values in all tests.

What I might actually do is offer a modifier attribute, where you can choose which modifiers to apply across the board. e.g. modifier="TRIM, NUM" would trim all fields and values in all tests, and make sure any numeric-based operations were treated as numbers instead of strings. In theory I think it’ll work; need to think it through to check it’s feasible and you can’t inadvertently create some paradox that defies the space-time continuum.

Not tonight though. Eyes closing…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#222 2009-03-26 12:45:45

rathersplendid
Plugin Author
From: London
Registered: 2008-05-02
Posts: 163
Website

Re: smd_if: Generic multiple if condition tests

Hey Stef, or anyone else who maybe able to help out,

I’m looking to, hopefully, use this plugin to create a conditional to work out the current month/date/time and change the page’s body class based on the result. What I want to do is use this to the change the page layout using CSS. Do you see what I mean?

Do you think this can be done? And if so, how?? My PHP is not pretty poor…

Thanks in advance guys.


Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle

Offline

#223 2009-03-26 13:08:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,426
Website GitHub

Re: smd_if: Generic multiple if condition tests

rathersplendid wrote:

create a conditional to work out the current month/date/time and change the page’s body class based on the result.

It kind of depends how clever you want to be. Are you going to want to read the date from anywhere, like the URL? (e.g. site.com/2009/03/26?) Or do you just care about changing the look based on “now” (and is “now” the user’s “now” or the server’s “now” because it may make a difference?)

smd_calendar has some supoprt for getting today’s date through the <txp:smd_cal_now /> tag but it’s probably less hassle to do something directly, like this:

<txp:variable name="theDay" value='<txp:php>echo strftime("%d");</txp:php>' />
<txp:variable name="theMonth" value='<txp:php>echo strftime("%m");</txp:php>' />
<txp:variable name="theYear" value='<txp:php>echo strftime("%Y");</txp:php>' />
<txp:variable name="theTime" value='<txp:php>echo strftime("%T");</txp:php>' />

and then use smd_if with txpvar: to do some basic checking like is theMonth > 6 and so on. Look at strftime for some ideas of how you can use it to get at the current bits of the current date/time to build your own output.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#224 2009-03-26 13:13:22

rathersplendid
Plugin Author
From: London
Registered: 2008-05-02
Posts: 163
Website

Re: smd_if: Generic multiple if condition tests

Stef, it needs to be now, and it doesn’t really matter for me about server time or user time because, for the moment at least, I only need to change the style by month.

I will have a look at what you suggested and get back to you; from the looks of it, I should be able to manage it now.

Cheers mate


Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle

Offline

#225 2009-04-04 23:05:10

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Hi Bloke,
For testing purposes, I’ve wrote this code:

<txp:smd_if logic="OR" field="urlvar:jquery" operator="eq,eq,eq" value="1.2.6,1.3.1,1.3.2">
  <script src="/js/jquery-{smd_if_jquery}.min.js" type="text/javascript"></script>
  <txp:else />
  <script src="/js/jquery-1.2.6.min.js" type="text/javascript"></script>
</txp:smd_if>

Wonder if it makes senses to have some kind of “default” (fallback) value for undefined and similar operators.
So, to have the ability to write something like this:

<txp:smd_if logic="OR" field="urlvar:jquery" operator="eq,eq,eq,undefined" value="1.2.6,1.3.1,1.3.2,1.2.6">
  <script src="/js/jquery-{smd_if_jquery}.min.js" type="text/javascript"></script>
</txp:smd_if>

There, the fallback value for undefined is the latest 1.2.6.

Last edited by maniqui (2009-04-04 23:11:12)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB