Textpattern CMS support forum

You are not logged in. Register | Login | Help

#381 2011-10-07 22:05:57

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

Re: smd_if: Generic multiple if condition tests

pafruu wrote:

I do not have a destination page, the form and the results are on the same page see here:

Doesn’t make any difference — in that case you just have to put <txp:adi_gps/> on the same page and then use <txp:if_variable> or <txp:smd_if> to detect if the rank variable’s been set with something.

when the <txp:adi_gps post=“1” /> I had no results at all

Hmmm, so let me get this straight in my head: you wrote an HTML form with a select list. The select list has name="rank" and the form has method="post" (lower case? Does it matter these days). Somewhere near the very top of the page flow you put a call to <txp:adi_gps post="1" /> and then somewhere further down the page you used <txp:variable name="rank" /> to display the value you submitted from the form’s submit button or onsubmit() method, and you saw no value displayed?

Without seeing any code, all I can say is that it should work. Can’t think of anything you missed. A puzzler.

I managed to make it work with good old javascript. Not pretty, but it works hehe!!

That would have been my other suggested approach. There are a few jQuery table sort plugins that allow you to click table headings and reorder data on the fly client-side. If you’re not paging results those are pretty handy.


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

#382 2012-01-28 01:01:10

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

Re: smd_if: Generic multiple if condition tests

v0.91 fixes some long-standing issues and adds a few new things as well:

  • Fixed pretext check for section/category (thanks saccade). Note that you must now use s if you want to test the current (URL-based) section
  • Added explicit checks for pretext, file, link, image, and article. These are handy if you don’t want to trust the inbuilt hierarchy, so you could specify field="image:name" to be absolutely clear on the name to which you were referring
  • Added var_prefix to allow nesting of smd_if tags without replacement clashes
  • Added :COUNT operator modifier (thanks the_ghost)
  • Added :ESC and :ESCALL modifiers
  • Finally fixed checks for defined / undefined so they’re actually useful

Hopefully this version allows you to do more stuff in a conditional funk. Enjoy.


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

#383 2012-03-01 01:27:10

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: smd_if: Generic multiple if condition tests

I try to filter articles using smd_if and smd_query.
I check the url to see if some urlvar are used then build a query to select specific articles.
If I view URL like this everything goes fine:

http://www.garfagnanabikers.it/itinerari/?foo=foo

but, how can I tell smd_if to execute normal (i.e. view all articles ) code when nothing urlvar are used?

Offline

#384 2012-03-01 01:40:54

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

Re: smd_if: Generic multiple if condition tests

wornout wrote:

http://www.garfagnanabikers.it/itinerari/?foo=foo

Does:

<txp:smd_if field="urlvar:foo" operator="undefined">
   // View all articles here
<txp:else />
   // View subset of articles based on value of foo here
</txp:smd_if>

work? Or you could switch the logic and use operator="defined". v0.91 should be able to do that kind of thing no problem.

Last edited by Bloke (2012-03-01 01:41:42)


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

#385 2012-03-01 07:20:40

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: smd_if: Generic multiple if condition tests

Can I do something like this?

<txp:smd_if field="urlvar:foo, urlvar:foo2" logic="and" operator="undefined">
  // View all articles here
<txp:else />
  <txp:smd_if value="urlvar:foo" operator="isused">
    // View subset of articles based on value of foo here
  </txp:smd_if>
  <txp:smd_if value="urlvar:foo2" operator="isused">
    // View subset of articles based on value of foo2 here
  </txp:smd_if>
</txp:smd_if>

Offline

#386 2012-03-01 14:28:11

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

Re: smd_if: Generic multiple if condition tests

wornout wrote:

Can I do something like this? <snip>

With v0.91, yes. Note that you may have to put the operator in twice in the first line:

<txp:smd_if field="urlvar:foo, urlvar:foo2" operator="undefined, undefined">
...

I’m not sure if it short circuits the operators or not, I can’t remember. Either way you don’t need logic="and" because that’s default behaviour.

An alternative construct, in theory to do the same thing:

<txp:smd_if field="urlvar:foo, urlvar:foo2" logic="or" operator="defined, defined">
  <txp:smd_if value="urlvar:foo" operator="isused">
    // View subset of articles based on value of foo here
  </txp:smd_if>
  <txp:smd_if value="urlvar:foo2" operator="isused">
    // View subset of articles based on value of foo2 here
  </txp:smd_if>
<txp:else />
  // View all articles here
</txp:smd_if>

Last edited by Bloke (2012-03-01 14:28:24)


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

#387 2012-03-01 21:18:54

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: smd_if: Generic multiple if condition tests

Thanks Stef!

Offline

#388 2012-06-05 13:14:45

lozmatic
Member
From: Melbourne, Australia
Registered: 2006-08-27
Posts: 259
Website

Re: smd_if: Generic multiple if condition tests

Hi,

I’m having troubled using this tag with a multi-select field defined using glz_custom_fields.

The field name is called Utilizzo and the options are:

Professionale
Educazione
Tempo-libero

In an article I have opted for the first two.

If I use <txp:smd_if field="Utilizzo" operator="contains" value="Professionale" >This is a test</txp:smd_if> I don’t get anything displayed.

If I change the field type to Select, than it works.

If I just display the value of the field using <txp:custom_field name="Utilizzo"/> I get: Educazione|Professionale

Any ideas?

Offline

#389 2012-06-07 12:05:53

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,163

Re: smd_if: Generic multiple if condition tests

I’d say it might be an upper/lowercase issue. If you hadn’t written this:

If I change the field type to Select, than it works.

On the other hand: the field type is saved in the txp_prefs table. Where (I’d bet any amount) smd_if never goes looking for its evaluations.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Online

#390 2012-06-07 12:34:24

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,222
Website

Re: smd_if: Generic multiple if condition tests

If you hadn’t written this: If I change the field type to Select, than it works.

Presumably it’s because you can’t choose multiple options with a normal select so there will be only one item and no | in the custom field value. In effect the operator contains is then eq.

I can’t immediately see why it’s not working either, unless the pipe (|) is being (mis)interpreted as an operator. Not sure if upper/lowercase should be an issue as smd_if is by default case-insensitive, although you can set that with the case_sensitive operator.

You might also want to try stripping out the | from the field by using smd_if’s filter attribute. I’ve not tried it but maybe:

<txp:smd_if field="Utilizzo" operator="contains" value="Professionale" filter="/[^a-zA-Z]+/" replace=" ">
   This is a test
</txp:smd_if>

If I’ve not made a mistake that should replace anything that is not A-Z or a-z in the field with a space…

Last edited by jakob (2012-06-07 12:37:39)


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB