Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2011-07-08 12:45:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,569
Website GitHub

Re: smd_multi_choice: select... case conditional-based output

frickinmuck

I’d be tempted to cheat like this:

<txp:variable name="has_var" value="0" />
<txp:smd_switch item="?coverageclient">
   <txp:smd_case type="empty">
      <txp:article_custom section="coverage" form="article_listing" limit="3" />
      <txp:variable name="has_var" value="1" />
   </txp:smd_case>
</txp:smd_switch>

<txp:if_variable name="has_var" value="0">
   <txp:smd_switch item="?coveragemediaoutlet">
      <txp:smd_case type="empty">
         <txp:article_custom section="coverage" form="article_listing" limit="3" />
         <txp:variable name="has_var" value="1" />
      </txp:smd_case>
   </txp:smd_switch>
</txp:if_variable>

<txp:if_variable name="has_var" value="0">
   <txp:smd_switch item="?coveragetype">
      <txp:smd_case type="empty">
         <txp:article_custom section="coverage" form="article_listing" limit="3" />
         <txp:variable name="has_var" value="1" />
      </txp:smd_case>
   </txp:smd_switch>
</txp:if_variable>

...

That way you only start a new switch if the one before it output nothing. And it saves having to use some hideously complex nesting.

Last edited by Bloke (2011-07-08 12:46:13)


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

#26 2011-07-08 14:26:48

frickinmuck
Member
Registered: 2008-05-01
Posts: 111

Re: smd_multi_choice: select... case conditional-based output

The only problem with that is, at least 3 of the variables will always be empty, therefore content will always display. The default recent articles list should only ever appear if all 4 of the variables are empty. It’s too bad there isn’t a way to check several variables at once, as in:

<txp:if_variable name="coveragemediaoutlet,coveragetype,coveragecause,coverageclient" value="0">
         <txp:article_custom section="coverage" form="article_listing" limit="3" />   
     </txp:if_variable>

or even

<txp:if_all_variables value="0">
         <txp:article_custom section="coverage" form="article_listing" limit="3" />   
     </txp:if_all_variables>

LOL

Last edited by frickinmuck (2011-07-08 14:30:12)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#27 2011-07-08 14:40:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,569
Website GitHub

Re: smd_multi_choice: select... case conditional-based output

frickinmuck wrote:

The default recent articles list should only ever appear if all 4 of the variables are empty. It’s too bad there isn’t a way to check several variables at once

smd_if can :-)

Did you say your variables came from the result of a user-submitted url variable? If so:

<txp:smd_if field="urlvar:coveragemediaoutlet,urlvar:coveragetype,urlvar:coveragecause,urlvar:coverageclient" operator="isempty">
   ... 
</txp:smd_if>

If you need to test txp:variables use txpvar instead of urlvar. You may also be better off with operator="undefined" if testing URL vars directly.

I don’t know if this is too little too late (or completely irrelevant) but can people filter by more than one of the variables at once? If not, why don’t you combine them into a single variable, then you can use multiple smd_case statements and fallthru=“1” to test them all in sequence.


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

#28 2011-07-08 18:59:03

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

Re: smd_multi_choice: select... case conditional-based output

frickinmuck wrote:

It’s too bad there isn’t a way to check several variables at once

I think it’s time to draw a new specialist plugin beneath the street lightings: cbe_if_variable.


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

Offline

#29 2011-07-09 01:38:18

frickinmuck
Member
Registered: 2008-05-01
Posts: 111

Re: smd_multi_choice: select... case conditional-based output

Of COURSE you have a solution up your sleeve, Stef! You just seem to be The Man! Thanks – it worked perfectly:

<txp:smd_if field="txpvar:coveragemediaoutlet,txpvar:coveragetype,txpvar:coveragecause,txpvar:coverageclient" operator="isempty">
<txp:article_custom section="coverage" form="article_listing" limit="3" />
</txp:smd_if>

No, there will only ever be one filter in use at a time. Coverage Type OR Coverage Client, etc. etc. But since this is working as desired now, I’m really happy with it as-is. Unless there’s some benefit to simplifying it besides the abstract value of “doing it correctly”. :^)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#30 2012-07-25 22:44:18

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

Re: smd_multi_choice: select... case conditional-based output

Feature request: a trim attribute for txp:smd_switch could come in handy when trying to exactly match (eq) strings that may come with leading/trailing spaces.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB