Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_multi_choice: select... case conditional-based output
v0.20 is released. Features:
- Added
type="empty"
and allowedvalue=""
/ 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
#14 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
Offline
#15 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
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
#17 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
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
#19 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
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:
- look at coverageclient
- is it empty? If so, do nothing
- if not, display the article
Your version did this:
- look at coverageclient
- is it empty? If so, do nothing
- 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
#21 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
#22 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
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
#24 2011-07-08 14:26:48
- frickinmuck
- Member
- Registered: 2008-05-01
- Posts: 118
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