Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#409 2013-01-21 08:05:54
Re: smd_if: Generic multiple if condition tests
gfdesign wrote:
if body or excert fields are empty.
Hmmm it works on my version 0.91 but I’m running it on a development site which uses a new version of Textile that has fixed a long-standing issue of rendering a tab character before content. So the problem might be the version of Textile that ships with Txp.
If you can look into your database via phpMyAdmin at an “empty” article, check the Body and Excerpt fields. You might find a rogue tab character or (maybe) a pair of empty <p>
tags. If so that’ll be why it’s not working so you’ll need to adjust your test for that character sequence instead of using value=""
.
For the record, both these constructs work with the new version of Textile installed:
<txp:smd_if field="excerpt" operator="isempty">
<p>empty excerpt</p>
</txp:smd_if>
and
<txp:smd_if field="body" operator="eq" value="">
<p>empty body</p>
</txp:smd_if>
(note operator is eq
not eg
).
You could try updating your version of Textile (and re-saving the empty article to test) but I’m not sure if it’s compatible with earlier installations any more. Might be worth a try, though. Make sure you get the 2.5 branch because development has recently split into two parallel branches. Backup the original file first of course.
Hope that helps.
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
#410 2013-01-21 12:16:30
- gfdesign
- Member
- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: smd_if: Generic multiple if condition tests
Hi Stef.
I’ve reviewed in the database of this site in an empty article and the fields seem to be empty as well (no there is any character). It is worth mentioning that in this website, does not use Textile, it uses an editor WYSWYG “hak_tinymce” plugin instead, but only in the body field. I had been using “chh_if_data” plugin for checking if body and excerpt fields are empty, but it fails when they have a few saved characters. In any case, could you be so kind as to explain how update textile version on my site?
Many thanks for your quick reply.
Regards
Offline
#411 2013-01-21 12:26:15
Re: smd_if: Generic multiple if condition tests
gfdesign wrote:
does not use Textile, it uses an editor WYSWYG
Hmm, that is weird. smd_if should detect the fact they’re empty then, as long as hak_tinymce doesn’t add anything to the fields on save. If there are no characters in the fields as shown in phpMyAdmin — even spaces or tabs — then I find it a bit strange.
explain how update textile version on my site?
Should be as simple as:
- Backup your existing
lib/classTextile.php
file. - Download the 2.5 version of
classTextile.php
and stick it in yourlib
folder. - Visit your article on the admin side and save it again so it gets run through Textile.
- Test smd_if with the new article.
But if you’re not using Textile then I may be wrong about it being the source of the error. Perhaps smd_if isn’t doing its job properly. You’re using 0.91, yes? I might need to put my debugging legs on.
Last edited by Bloke (2013-01-21 12:27:16)
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
#412 2013-01-21 14:46:32
- gfdesign
- Member
- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: smd_if: Generic multiple if condition tests
Ok, I’ve followed the steps but it did not work. When I did it, and then I try to access to any article then loads this page https://github.com/netcarver/textile/tree/2.5 on my Txp site :| .Other thing caught my attention was that my classTextile.php file is 51Kb (2.2v) and the new one (2.5v) is 666Kb. Can there be so much difference each other? (Must be as you have mentioned about parallel branches)
For now, it is not so important because I’m working on a test site in a free hosting account, but I just wanted comment it. Surely, many PHP functions are disabled and it doesn’t work as expected. I’ll have to try on in a paid hosting account.
BTW, yes, I’m using smd_if 0.91 on Txp 4.4.1 (PHP version 5.2.*)
Many thanks for your time.
Last edited by gfdesign (2013-01-21 14:55:54)
Offline
#413 2013-01-21 14:55:16
Re: smd_if: Generic multiple if condition tests
gfdesign wrote:
the new one (2.5v) is 666Kb. Can there be so much difference each other?
Nope. The new one should be about 91KB. See the raw file directly and do a Save Page As from your browser to obtain a copy that you can drop into your Textpattern installation.
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
#414 2013-01-21 15:17:30
- gfdesign
- Member
- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: smd_if: Generic multiple if condition tests
Sorry, You’re right. It’s 91Kb. My bad :S In any case, it didn’t work neither. I went to check back on the database, but fields are still empty (even saving the articles again). If I have best luck, I’ll let you know.
Best regards
Offline
#415 2013-07-21 01:32:51
Re: smd_if: Generic multiple if condition tests
Recent upgrade to textpattern and smd_if broke part of my site?
I have a page with a URL of the form /section/category/ which previously worked, and it works for pages I only use textpattern tags.
However, on one page I’m using smd_if and debugging shows the following:
<txp:smd_if field="category" operator="eq" value="our_story">
[<txp:smd_if field="category" operator="eq" value="our_story">: false]
</txp:smd_if>
The category not matching is odd as earlier in the same debug log I see:
<txp:page_title />
[SQL (6.29425048828E-5): select title from txp_category where name='our_story' and type='']
Which suggests to me that textpattern is recognizing ‘our_story’ as the category.
Thoughts?
Offline
#416 2013-07-21 08:40:26
Re: smd_if: Generic multiple if condition tests
mericson wrote:
<txp:smd_if field=“category” operator=“eq” value=“our_story”>
My guess is that it’s because category
(somewhat bizarrely, but I had my reasons) isn’t an officially supported field
. The correct way to check for ‘global’ (URL) category is by using field="c"
.
In versions up to 0.91 this was somewhat loosely enforced so ‘category’ was tolerated, and probably worked in most situations (although failed in others) because of a subtle oversight in my code. I closed the loophole in v0.91 when I enhanced the field
attribute to work with explicit arrays.
Sorry for any hassle it’s caused. Give it a go with ‘c’ instead of ‘category’ and see if it works any better.
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
#417 2014-03-02 18:58:00
Re: smd_if: Generic multiple if condition tests
Howdy Brainiacs.
Why does the following return “NOT SO MATCH”?
<txp:variable name="myvar">red green blue</txp:variable>
<txp:smd_if
field="txpvar:myvar"
operator="contains"
logic="or"
value="purple/pink/red">
A MATCH!
<txp:else/>
NOT SO MATCH
</txp:smd_if>
I’m losing the last of my 1/8 inch tall hair.
Offline
#418 2014-03-02 19:23:35
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,310
Re: smd_if: Generic multiple if condition tests
My frustrations were mostly caused by delimiters. Have you tried colons as field separators instead of slashes?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#419 2014-03-02 22:21:13
Re: smd_if: Generic multiple if condition tests
mrdale wrote #279362:
Why does the following return “NOT SO MATCH”?
Because you can’t use contains
to test a series of values. smd_if tests each given field
against each given value
using each given operator
. Your example is doing this:
Does my txp:var contain the string “purple/pink/red”?
And that’s it. The answer is no, it does not. The fact that using the slashes splits the value
string into three separate parts is immaterial at present because the list_delim
(forward slash by default) only comes into play for in
, notin
, between
and range
operators. Perhaps it should allow you to use it for contains
as well, can’t remember why I didn’t do it. Perhaps it’s because of the way contains
works under the hood (it’s a bit different to the other operators), or perhaps I just didn’t consider it. I’ll check it out and if it can be extended, I’ll do so.
Regardless, in the meantime, the correct way to get it to match more than one thing is to repeat the field and operator once for each value:
<txp:smd_if
field="txpvar:myvar, txpvar:myvar, txpvar:myvar"
operator="contains, contains, contains"
logic="or"
value="purple,pink,red">
A MATCH!
<txp:else/>
NOT SO MATCH
</txp:smd_if>
That does one test for each value. But note that if you’re trying to search for values that contains spaces you’ll need to add :NOSPACE
to the operator or things go a bit haywire.
EDIT: just checked. Not possible to short circuit contains
to use multiple values in the plugin’s present form. Would need to introduce a new operator for this and it’s a bit messy.
Last edited by Bloke (2014-03-02 22:28:40)
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
#420 2014-03-03 04:01:53
Re: smd_if: Generic multiple if condition tests
Gotcha! I muddled through and got the same result and that works. I can definitely type a few more characters when I need to, so don’t bother contorting your indispensable plugin’s code into ugly shapes.
Offline