Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2010-07-28 23:17:46

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

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

Beware: another not so useful bug report below (typical of me).

Bloke, while hacking your plugin, you may want to look at the code related to the default attribute of <txp:smd_case />. I recall that last time I tried to set a default case, it didn’t work for me.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#14 2010-07-29 06:19:29

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

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

maniqui wrote:

I recall that last time I tried to set a default case, it didn’t work for me.

Thanks for the memory jog, yeah. That’s the bug I found. From what I can recall, if you specify the value as well as default it works fine but default on its own always fails to match (or something like that). I can’t find the test case on my dev site where I was testing the bug so I’ll have to start again. Hmmph.


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

#15 2010-08-02 22:31:22

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

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

v0.20 is released. Features:

  • Added type="empty" and allowed value="" / empty case statement (thanks gomedia)
  • Added var_prefix to allow nested switches
  • Fixed default case firing unnecessarily
  • Fixed problem with multiple switch tags on a page

I think I squished everything that was remotely buglike in the process. As always, any problems or cool use cases, post them here.


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

#16 2010-08-02 23:00:09

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

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

Bloke wrote:

v0.20 is released.

Thanks Stef.

Offline

#17 2011-07-05 17:08:44

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

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

This is a FANTASTIC plugin – mucho gracias.

My situation is a simple either/or one. If a value is empty, do x, if it’s not empty, do y. Is there a way to simply check if a value is not empty? Checking against the type of content in that value isn’t suitable, because there are so many different possible valid values.


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

#18 2011-07-05 18:13:07

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

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

frickinmuck wrote:

Is there a way to simply check if a value is not empty?

Sure: don’t use this plugin :-)

<txp:variable name="has_content">value or tag to check goes here</txp:variable>

<txp:if_variable name="has_content" value="">
   // do x
<txp:else />
   //do y
</txp:if_variable>

Does that help?


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

#19 2011-07-05 20:03:37

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

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

That would be perfect, except I’m checking against multiple variables, as in this post, and I need to determine if each of those variables has content, then display content accordingly.


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

#20 2011-07-05 20:15:02

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

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

Hang on a mo. Just trying to wrap my head round what you’re doing (and failing). Before I go totally bonkers with your logic, can I just ask why the code you posted here isn’t using <txp:smd_case default="1"> to catch the condition when there are no matches?

As it stands, your article tag is always going to display content. What I think you want is for it to output its content if it contains something. If you’re testing for type="empty" then, by definition, everything inside the default <txp:smd_case> must contain something, i.e. NOT empty.

Or have I misunderstood?


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

#21 2011-07-06 04:23:02

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

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

OK, maybe I’m just misunderstanding how to use this, then. I’ve got 4 variables that I need to check, and so far I’ve only gotten so far as testing them separately, as until I can wrap my head around that, I’m not going to have much hope of dealing with nesting them, etc. Here’s the 4 cases I have:

<txp:smd_switch item="?coverageclient">
   <txp:smd_case type="empty">
   </txp:smd_case>
      <txp:article_custom section="coverage" coverageclient='<txp:variable name="coverageclient" />' form="article_listing" limit="999" />
</txp:smd_switch>
<txp:smd_switch item="?coveragemediaoutlet">
   <txp:smd_case type="empty">
   </txp:smd_case>
      <txp:article_custom section="coverage" coveragemediaoutlet='<txp:variable name="coveragemediaoutlet" />' form="article_listing" limit="999" />
</txp:smd_switch>
<txp:smd_switch item="?coveragetype">
   <txp:smd_case type="empty">
   </txp:smd_case>
      <txp:article_custom section="coverage" coveragetype='<txp:variable name="coveragetype" />' form="article_listing" limit="999" />
</txp:smd_switch>
<txp:smd_switch item="?coveragecause">
   <txp:smd_case type="empty">
   </txp:smd_case>
      <txp:article_custom section="coverage" coveragecause='<txp:variable name="coveragecause" />' form="article_listing" limit="999" />
</txp:smd_switch>

I guess that since the values are going to be stuff like, “?coveragemediaoutlet=CNN+Situation+Room”, I got confused as to what to validate for. There won’t be many numbers, but it’s not just letters, either. It doesn’t help that I’m trying to do all this when my brain is at about 70%. I used to be able to reason all this kind of stuff out a lot better, but these days I just get confused so easily, I feel like a turtle that’s rolled over on its back. :^)

Last edited by frickinmuck (2011-07-06 04:23:20)


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

#22 2011-07-06 09:15:06

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

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

frickinmuck

Doesn’t this do what you’re after then:

<txp:smd_switch item="?coverageclient">
   <txp:smd_case type="empty">
   </txp:smd_case>
   <txp:smd_case default="1">
      <txp:article_custom section="coverage" coverageclient='<txp:variable name="coverageclient" />' form="article_listing" limit="999" />
   </txp:smd_case>
</txp:smd_switch>

And repeat for the other 4 vars. That code says:

  1. look at coverageclient
  2. is it empty? If so, do nothing
  3. if not, display the article

Your version did this:

  1. look at coverageclient
  2. is it empty? If so, do nothing
  3. display the article, regardless of the outcome of the above test

Subtle difference, but an important one. The plugin only ever takes one branch (one case statement) unless you allow fallthru, so that structure should do your bidding. Ummm, I think.

Last edited by Bloke (2011-07-06 09:15:59)


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

#23 2011-07-06 16:34:15

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

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

That’s not a subtle difference at all! I consider it a fairly blatant one! hehe. Thanks so much. It’s working brilliantly now. You’ve been a tremendous help.


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

#24 2011-07-08 03:08:06

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

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

I’ve run into one last issue that I can’t seem to get my head around. I want a few articles to appear by default, but then when someone selects a parameter from the pull-down menus (i.e. the URL variables are in play), the only articles that appear are the ones selected. So, for example, by default the most recent 3 articles in the section appear, but then if the user chooses a media outlet “BBC”, then they only see the BBC articles.

This seemed simple at first, because I have the landing page for that section set to a specific article. I just placed a similar bit of code in the article as is on the page template itself, and it worked great:

<txp:smd_switch item="?coverageclient">
   <txp:smd_case type="empty">
   <txp:article_custom section="coverage" form="article_listing" limit="3" />
   </txp:smd_case>
</txp:smd_switch>

The problem, of course, is that it only works for “coverageclient”. If I select one of the other variables (i.e. “coveragemediaoutlet”), then of course the variable “coverageclient” is now empty, so I get the 3 latest articles, followed by the articles from the media outlet that was selected. (i.e. as in the previous example, the 3 latest articles from the section followed by the articles from the “BBC”). I guess I need to nest them or get it to check against all 4 variables, and if they’re all empty, then show the default 3 recent articles from the section. I just can’t get my head around how. Any ideas?


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

Board footer

Powered by FluxBB