Textpattern CMS support forum

You are not logged in. Register | Login | Help

#351 2010-09-19 21:15:28

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

New check request

<txp:variable name="test_me">1,2,3,4</txp:variable>
<txp:smd_if field="txpvar:test_me" operator="ge:COUNT" value="3">
  Yes, there are more than 3 value. We have _{smd_if_test_me_count}_ values in list
<txp:else />
  There are 3 or less values in list.
</txp:smd_if>

And when we run it we would get:

Yes, there are more then 3 value. We have _4_ values in list

And we can use list_delim attr for changing coma “,” to something else.

I’d like to use plugin in such case to check if article_image (or cf) has more than 2 id’s. Of course, i can create little php and insert counter in some txp:variable, but using only smd_if is such a txp-way method! :)


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

#352 2010-09-28 23:28:08

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 478

Re: smd_if: Generic multiple if condition tests

Stupid me:
How can I use the article’s section as field?
field=“section” does work on the section itself.

I need to compare the current article’s section (in form default) against a list of user-related sections, operator = “in”, to filter out articles which belong to another section.

Offline

#353 2010-09-28 23:49:32

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

Re: smd_if: Generic multiple if condition tests

saccade wrote:

How can I use the article’s section as field?

field="section" should work. Can you post the tag in context with what you’re trying to do please and I’ll see if I can figure out what’s going on. You could also try adding debug=“4” so you can see all the various global ‘THIS’ arrays. The items on the left of the => signs are all names you can use in the field attribute. Might give you some insight into the logic.

the_ghost

I’ll try and get something working along these lines. Won’t be this week though.


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

#354 2010-09-29 00:14:38

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 478

Re: smd_if: Generic multiple if condition tests

This goes into my default-form:

<txp:smd_if field="section" operator="in" list_delim="," value='<txp:sac_special_groups_privs />' >   ...   <txp:else />   ...  </txp:smd_if>

<txp:sac_special_groups_privs /> lists some allowed sections: e.g. “articles,about,whatever”

But obviously “section” doesn’t work, when viewing the default page (where articles from other sections gather). First I thought it should work, because it showed me an article, but then it didn’t – e.g. when listing more than one. I tried the same in a listform but without improvement.

Replacing my own tag with a hardcoded list doesn’t work too.
Always the “else”-part is rendered :(
(I did an output of all variables. articles_sections are definitely part of the value’s given)

Last edited by saccade (2010-09-29 00:31:03)

Offline

#355 2010-09-29 00:30:17

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

Re: smd_if: Generic multiple if condition tests

saccade wrote:

But obviously “section” doesn’t work

Ah, right. It does work but you’re falling foul of one of the default attributes. param_delim defaults to a comma and since you’re using the comma for list_delim as well the plugin is seeing the commas in the value attribute and simply splitting them using param_delim (it takes precedence).

To work round it, specify param_delim as some other character like a pipe or something.

Last edited by Bloke (2010-09-29 00:30: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

#356 2010-09-29 00:36:40

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 478

Re: smd_if: Generic multiple if condition tests

Sorry, changing param_delim doesn’t solve my problem.
Obviously: in individual_article_mode the if-part is rendered.
But in article-list-mode only the else-part is working.

EDIT
I changed my values delimiter to / but it didn’t work either

Last edited by saccade (2010-09-29 00:43:32)

Offline

#357 2010-09-29 00:51:38

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 478

Re: smd_if: Generic multiple if condition tests

I did some more tests (fiddling with category queries in sections): field=“section” doesn’t refer to the article’s section in any case, but only to the section present from the url.

Offline

#358 2010-09-29 01:03:53

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

Re: smd_if: Generic multiple if condition tests

saccade wrote:

But in article-list-mode only the else-part is working.

Right then. I think I’ve figured it out. It’s a bit of a dunce move on my behalf. Canyou just try this please. Edit line 24(ish) of the plugin from:

"section" => '$pretext["s"]',

to:

"s" => '$pretext["s"]',

Then refresh your article list version. As you found, the plugin is pulling ‘section’ from $pretext and never getting to the ‘section’ entry in $thisarticle. The pretext array always refers to the global (URL) section wheras the one in $thisarticle refers to the article section.

If that works I’ll update the plugin at some point to fix this glaring oversight.


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

#359 2010-09-29 01:04:16

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

Re: smd_if: Generic multiple if condition tests

Ah, so you want to test the section of the currently iterated article:
You may try this (combined with the other advice given by Bloke):

<txp:smd_if field='<txp:section />' operator="in" value='<txp:sac_special_groups_privs />' >   ...   <txp:else />   ...  </txp:smd_if>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#360 2010-09-29 01:12:24

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 478

Re: smd_if: Generic multiple if condition tests

Bloke: Great – it is working now! Thanks so much for working late in the night :)
Maniqui: Didn’t try this out, but this seems reasonable. Thanks too for late-night-helpfulness :)

Offline

Board footer

Powered by FluxBB