Textpattern Forum

You are not logged in. Register | Login | Help

#111 2008-10-01 07:38:41

visualpeople
Member
From: Corvallis, Oregon - USA
Registered: 2005-11-16
Posts: 70
Website

Re: smd_if: Generic multiple if condition tests

I’m having the same problem as mapu —

When I use begins (or contains) with urlvar: I’m getting the same “Parse error…”

Just in case, here’s my code:

(urlvar is ?partners=8_something)

<txp:smd_if field="urlvar:partners" operator="begins" value="8">
<p>yes</p>
<p>{smd_if_partners}</p>
<txp:else />
 <p>no</p>
<p>{smd_if_partners}</p>
</txp:smd_if>

And it’s outputting the actual text {smd_if_partners} — not 8_something

All other operators seem to be working just fine.

Last edited by visualpeople (2008-10-01 07:46:01)

Offline

#112 2008-10-01 08:35:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,916
Website

Re: smd_if: Generic multiple if condition tests

maxvoltar

Yes, posted is supported, but because there’s no concept of ‘future’ the only way you can do it is to compare the posted date with the current time now. Perhaps like this (untested):

<txp:smd_if operator="posted" operator="gt" value='<txp:php>echo time();</txp:php>'>
  // Article is not yet publisherd
<txp:else />
  // Article is available now
</txp:smd_if>

(that might only work in TXP 4.0.7. You could, as MattD suggested, use txp:variable to assign the value from PHP’s time() function on your page somewhere and then use it as a comparison)

EDIT: if you temporarily add debug="2" to the tag, you can see all the variables that smd_if can ‘see’. They are listed under “THIS ARTICLE” and “PRETEXT”.

mapu / visualpeople

Rats, you found an oversight in my logic. Thanks for letting me know. Will fix it, watch this space.

Last edited by Bloke (2008-10-01 08:41:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#113 2008-10-01 09:41:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,916
Website

Re: smd_if: Generic multiple if condition tests

OK, v0.71 [ zipped ] fixes what mapu/visualpeople spotted, many thanks to them for highlighting my coding faux pas. It fixes the fix I introduced in v0.7 that visualpeople spotted originally about the empty custom fields. I have now taken a different approach with regards testing for empty values that I hope will alleviate these errors.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#114 2008-10-01 10:16:40

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_if: Generic multiple if condition tests

Bloke wrote:

OK, v0.71 [ zipped ] fixes what mapu/visualpeople spotted, many thanks to them for highlighting my coding faux pas. It fixes the fix I introduced in v0.7 that visualpeople spotted originally about the empty custom fields. I have now taken a different approach with regards testing for empty values that I hope will alleviate these errors.

Wow, that was fast!

But I’m still getting some odd behaviour with 0.71 when using begins or contains in combination with <txp:else /> with TXP telling me that smd_if is an unknown tag. Without <txp:else /> it is working wonderful, but because of a missing NOT condition I need <txp:else />.

Offline

#115 2008-10-01 10:24:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,916
Website

Re: smd_if: Generic multiple if condition tests

mapu wrote:

TXP telling me that smd_if is an unknown tag.

Very odd. I was just using it with begins and <txp:else /> to track down the bug and never noticed anything not working. I can have a closer look at the code. Would you please post the tag syntax you are using and / or any relevant info that pops out if you add debug="1" to smd_if. Thanks.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#116 2008-10-01 12:01:43

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_if: Generic multiple if condition tests

Bloke wrote:

Would you please post the tag syntax you are using and / or any relevant info that pops out if you add debug="1" to smd_if. Thanks.

Shame on me, I had a typo in my code. Sorry for any inconvinience!

But I have another question: How do I test agains some HTML-Code? The body field usually begins with a <p> but when trying to test agains it the plugin just outputs nothing (also not with debug="1"). The contains operator is not useful for my purpose.

Offline

#117 2008-10-01 13:56:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,916
Website

Re: smd_if: Generic multiple if condition tests

Yes, the body tag (among others) contains HTML and, as you have found, it is difficult to catch this exactly. You would have to use the entities like &lt; etc to match it exactly. Even then, those fields also tend to begin with a space or two which makes it very difficult to test against.

So, I have added an option in v0.72 [ zipped ] that allows you to remove HTML/PHP tags and any extraneous spaces from a field or value. Just add :NOTAGS to the end of any field or value and it’ll do the rest.

Does that help?

Last edited by Bloke (2008-10-01 13:56:57)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#118 2008-10-01 14:25:44

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_if: Generic multiple if condition tests

Well, not exactly, because I DO want to test the HTML-Code. I want to test, if an article starts with a link. Something like this:

<txp:smd_if field="body" operator="begins:NOSPACE" value="<p><a">
...

Let me say thank you for all your effort. This plugin makes me feel like a programmer :)

Offline

#119 2008-10-01 14:40:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,916
Website

Re: smd_if: Generic multiple if condition tests

mapu wrote:

Well, not exactly, because I DO want to test the HTML-Code.

Ah, simple fix I think. The :NOSPACE directive is currently only used for the ‘is’ operators (isalpha, isnum, ispunct, etc). So what’s happening is the begins operator is not stripping out the spaces before the first <p> in the article.

Try this as a test and if it works I’ll make another version that does this by default (sorry, I’m going to make you feel more like a programmer now :-) Scroll down the plugin code to about line 64 and look for a line that starts : $spaceOps = "isnum, isalpha, isalnum...". Change it to:

$spaceOps = "isnum, isalpha, isalnum, islower, isupper, ispunct, begins, contains, ends";

Then run your example again. It should now strip spaces out of the body tag but leave the HTML tags intact, thus allowing you to test for <p><a>.

Last edited by Bloke (2008-10-01 14:40:48)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#120 2008-10-01 14:56:56

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_if: Generic multiple if condition tests

It is stripping out the leading spaces now, but it seems it still doesn’t like the <p><a part of it. Even with &lt; or &gt; – well, with &lt; and &gt; it works but the result is FALSE. Maybe there is a way to escape the <’s and >’s ?

Offline

Board footer

Powered by FluxBB