Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#133 2008-10-31 14:05:04

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

Re: smd_if: Generic multiple if condition tests

the_ghost wrote:

It seems that smd_if turns off case-insensetivity when accessing custom_fields by name.

Yes it does, because TXP does so when it stores them. The case_sensitive attribute only governs the_contents_ of the fields, not the field names themselves.

Since TXP 4.0.5 the custom field name has been automatically lower-cased internally. Since smd_if checks $thisarticle for the match (“internally”) you have to specify it in lower case. I thought I mentioned this in the help, but maybe I forgot: sorry.

I seem to recall that I didn’t want to force everything in the field attribute to be lower case automatically (though I could…) in case you wanted to check some mixed-case string that wasn’t a TXP field, possibly in combination with the case_sensitive attribute. Can’t think of an example off the top of my head, but I believe it left a little more flexibility.

visualpeople

I haven’t forgotten about this request. Will try and duplicate your setup on my test site and get thinking… :-)

Last edited by Bloke (2008-10-31 14:05:52)


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

#134 2008-11-08 19:43:40

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

Re: smd_if: Generic multiple if condition tests

I though my brain was already dominating your plugins, Mr. Bloke, but it seems it’s still the other way around.
On a form called by smd_gallery, I’m trying:

<txp:smd_if field="NULL" operator="eq" value="{title}">
  No caption. And this should also be emtpy = {title}
<txp:else />
  There is a caption.
</txp:smd_if>

But it’s always returning “No caption. And this should also be emtpy = thecaption”, even when the image has a caption.
Other parts of the same form are working properly.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#135 2008-11-08 20:02:01

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

Re: smd_if: Generic multiple if condition tests

By the way, this didn’t work either:

<txp:smd_if field="{title}" operator="isempty">...

or

<txp:smd_if field="caption" operator="isempty">

The last one is based on the plug-in instructions saying:

Supports most major article, file, image and link variables such as section, category, custom fields, id, query string, author, body, excerpt, yahde yahde, plus url vars, server vars, txp vars, php vars, and sub-category/parent checking
[…]
Use the tag in any page, form or article context. Can also be used inside file, image or link lists to take action depending on attributes of the current item.
[…]
other article/file/link field (e.g. body, excerpt, article_image, keywords, linkanme, filename, downloads, …)

(although the last sentence quoted doesn’t say anything about images).

Last edited by maniqui (2008-11-08 20:02:21)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#136 2008-11-08 23:18:30

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

Re: smd_if: Generic multiple if condition tests

maniqui wrote:

it’s always returning “No caption. And this should also be emtpy = thecaption”, even when the image has a caption.

Weird, it works on my test page using smd_if v0.74. If you put debug="1" (or 2) on, do you get any indication why it might be failing the tests?

I have, however, uncovered a bug when using it this way round. For some reason, I have not escaped bad chars like apostrophes (stupid mistake I’ll have to hunt down) so if you have any apostrophes or other deal-breaking characters in your captions, the test will fail. In site debugging mode you’ll see a horrible error message. I will fix that.

By the way, this didn’t work either: <txp:smd_if field=”{title}” operator=“isempty”>…

No, sadly it won’t. The plugin will just cry if it sees an empty title. This is a known limitation and is documented.

Supports most major article, file, image and link variables

Ah, yes, that last one won’t work (yet) either because true image support isn’t built into the core yet. Remember my image patch I’m slowly refining? smd_if has jumped the gun and knows about the $thisimage variable (ruud has indicated it will likely become a reserved variable at some stage in the product).

Put simply, inside a hypothetical image_list tag in a future version of TXP, you could test the caption on your default ‘images’ form as it rendered each matching image. Sadly, none of that functionality exists right now so your last example is looking at the article for a field called ‘caption’ (which doesn’t exist) so the test fails.

I’m curious about the reason your NULL example doesn’t work, though. If you have any more info that might help me track it down I’d appreciate it.


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

#137 2008-11-09 15:15:39

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

Re: smd_if: Generic multiple if condition tests

Bloke wrote:

I have, however, uncovered a bug when using it this way round. For some reason, I have not escaped bad chars like apostrophes (stupid mistake I’ll have to hunt down) so if you have any apostrophes or other deal-breaking characters in your captions, the test will fail.

Voilà! The caption had some double quotes and that was the problem. Sorry for not have testing further to arrive to this conclusion by myself.

me: By the way, this didn’t work either: <txp:smd_if field=”{title}” operator=“isempty”>…

No, sadly it won’t. The plugin will just cry if it sees an empty title. This is a known limitation and is documented.

Yes, I forgot to say “as documented”. :)
I usually RTFM, even in your plugins where help are like a Bible :D.
Funny documentation btw.

I’m curious about the reason your NULL example doesn’t work, though. If you have any more info that might help me track it down I’d appreciate it.

As said above, the double quotes didn’t have mercy with your plugins. By the way, I’m also processing the caption with upm_textile so textile can be used on captions. But I think that isn’t related to our problem at all. Or may be?

This is the form as I’m using it now:

  <txp:smd_if field="NULL" operator="not" value="{title}">
  <div class="panel-column text-column">
    <div class="panel-text">
        <txp:upm_textile>{title}</txp:upm_textile>
    </div><!-- .panel-text -->
  </div><!-- .text-column -->
  </txp:smd_if>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#138 2008-11-14 14:35:37

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hello,

I was wonderig if this can work

<smd_if field=month operator=eq value=“2005-04, 2005-05”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<else>
<txp:article limit=“5” form=“dagboek” sort=“Posted asc” />
< /smd_if>

Regards,

Roelof

Offline

#139 2008-11-14 14:46:36

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

Re: smd_if: Generic multiple if condition tests

roelof wrote:

I was wonderig if this can work <snip>

To achieve what, exactly?

If you wish to check if the ?month variable in the URL is either 2005-04 or 2005-05 then you would need this:

<txp:smd_if field="urlvar:month, urlvar:month" operator="eq, eq" value="2005-04, 2005-05" logic="or">
  <txp:article limit="1" form="dagboek" sort="Posted asc" />
  <txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
<txp:else>
  <txp:article limit="5" form="dagboek" sort="Posted asc" />
</txp:smd_if>

Otherwise, I’m not quite sure what it is you are trying to do. Please elaborate if that is not it.

EDIT: or use the new in operator like this:

<txp:smd_if field="urlvar:month" operator="in" value="2005-04/2005-05">

EDIT2: add txp: in front of the plugin name ;-)

Last edited by Bloke (2008-11-14 17:04:45)


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

#140 2008-11-14 14:59:31

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hoi Bloke,

It’s correct that i want to check the value of the month variable in the url.
One question : Can i nest it ?

Roelof

Offline

#141 2008-11-14 15:04:16

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

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Can i nest it ?

You can’t nest smd_if calls under TXP 4.0.6, no. The same as all other tags. That’s partly the reason I added the in operator (see Edit in above post), so you could check multiple values without nesting. Under 4.0.7 the nesting restriction is lifted.

Last edited by Bloke (2008-11-14 15:04:36)


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

#142 2008-11-14 15:49:32

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

oke,

It’s a pity but i can live with it.
Thank you for the help en tips.

Roelof

Offline

#143 2008-11-14 16:51:04

roelof
Member
Registered: 2005-03-27
Posts: 647

Re: smd_if: Generic multiple if condition tests

Hoi Bloke,

I have a problem.

I use this in my page template :

<txp:if_section name=”,default”>
<txp:if_category name=“zwangerschap,jaar1,jaar2,jaar3,jaar4”>
<smd_if field=“urlvar:month” operator=“in” value=“2005-04”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
</smd_if>
<smd_if field=“urlvar:month” operator=“in” value=“2005-02, “2005-03”>
<txp:article limit=“5” form=“dagboek” sort=“Posted asc” />
</smd_if>
<txp:else />
<txp:article_custom section=“voorpagina” form=“default” />
</txp:if_category>
</txp:if_section>

But if i look in the tag trace the plugin isn’t doing one thing.
I have enabled it in the plugin sections.

Do you have any idea why nothing happens with the plugin.

Roelof

Offline

#144 2008-11-14 17:02:59

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

Re: smd_if: Generic multiple if condition tests

roelof wrote:

Do you have any idea why nothing happens with the plugin.

You need to add txp: in front of the smd_if plugin name ;-)

Sorry, I didn’t spot that when I copy n pasted your example, I’ve gone back and fixed the code in my post.

Last edited by Bloke (2008-11-14 17:05:50)


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

Board footer

Powered by FluxBB