Textpattern CMS support forum

You are not logged in. Register | Login | Help

#131 2008-10-24 20:00:14

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

Re: smd_if: Generic multiple if condition tests

Stop me if this is impossible… It seems like I should be able to do it, but I can’t quite get my puny little brain around it.

I want to serve up a random banner ads and I think I can use the smd-trifecta to achieve this. It has to be a random banner ad (thanks smd_random_banner!) but it might be a flash ad, or it might be a .gif image (no problem, thanks to smd_random_text!) but what if there are no ads in either the images or files section? I think smd_if should be able to come to my rescue, but I haven’t been able to get it to work yet…

here’s the code that’s working so far:

<txp:smd_random_text type="string" source="file|image">
<txp:smd_random_banner category="top_horizontal_banner" imgclass="ad" link_in="caption" mode="{smd_rnd_txt}" nv_delim="::" global_params="playerversion::9;width::728;height::90;"/>
</txp:smd_random_text>

I was thinking I need to call a form that lists all of the images in the “top_horizontal_banner” category and then if nothing shows up in that form, then display files… but that’s where I can’t figure out exactly what to do with those results.

Then what happens if there are images with the category “top_horizontal_banner” but no files with the category “top_horizontal_banner”?

Offline

#132 2008-10-31 00:56:44

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_if: Generic multiple if condition tests

It seems that smd_if turns off case-insensetivity when accessing custom_fields by name. I have custom field named “Podmenu”. I have such code:

<txp:smd_if field="Podmenu,txpvar:ind_art" operator="isnum,eq" value=",1" logic="or" debug="2">

But this allways fires as “false”. When I added debug="2" i saw:

THIS ARTICLE:
array (
  'thisid' => '10',
  'posted' => '1220084884',
  'modified' => '1220178592',
  'annotate' => '0',
  'comments_invite' => '',
  'authorid' => 'admin',
  'title' => 'Подраздел 2',
  'url_title' => 'podrazdel-2',
  'category1' => '',
  'category2' => '',
  'section' => 'okrugi',
  'keywords' => '',
  'article_image' => '',
  'comments_count' => '0',
  'body' => '	<p>lalala</p>',
  'excerpt' => '',
  'override_form' => '',
  'status' => '4',
  'podmenu' => '3', <<<<<<<<<<<
  'file_id' => '',
)

Look at highlighted string – custom_field is written in lowercase.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,749
Website

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
Moderator
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
Moderator
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: 8,749
Website

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
Moderator
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: 8,749
Website

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

Board footer

Powered by FluxBB