Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#241 2009-07-09 12:22:22
Re: smd_if: Generic multiple if condition tests
Bloke as always you are my hero….. thanks for the clarification!
Offline
#242 2009-08-16 20:27:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: smd_if: Generic multiple if condition tests
My first-time use of smd_if :) As always: great plugin, thanks Stef! I need to add a class to the html body tag, depending on the season. I’ve managed to do it like this:
<txp:variable name="thisMonth" value='<txp:php>echo strftime("%m");</txp:php>' />
<txp:variable name="thisDay" value='<txp:php>echo strftime("%e");</txp:php>' />
<txp:smd_if field="txpvar:thisMonth, txpvar:thisMonth" operator="eq, eq" logic="or" value="01, 02">winter</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth" operator="eq" value="03">
<txp:smd_if field="txpvar:thisDay" operator="le" value="21">winter<txp:else />spring</txp:smd_if>
</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth, txpvar:thisMonth" operator="eq, eq" logic="or" value="04, 05">spring</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth" operator="eq" value="06">
<txp:smd_if field="txpvar:thisDay" operator="le" value="21">spring<txp:else />summer</txp:smd_if>
</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth, txpvar:thisMonth" operator="eq, eq" logic="or" value="07, 08">summer</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth" operator="eq" value="09">
<txp:smd_if field="txpvar:thisDay" operator="le" value="21">summer<txp:else />autumn</txp:smd_if>
</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth, txpvar:thisMonth" operator="eq, eq" logic="or" value="10, 11">autumn</txp:smd_if>
<txp:smd_if field="txpvar:thisMonth" operator="eq" value="12">
<txp:smd_if field="txpvar:thisDay" operator="le" value="21">autumn<txp:else />winter</txp:smd_if>
</txp:smd_if>
but it’s such a lot of code… I’ve tried using REQUEST_TIME, but I can’t figure it out. (Of course the plugin is not to blame, it’s just my limited knowledge…) This code is obviously wrong:
<txp:smd_if field="svrvar:REQUEST_TIME, svrvar:REQUEST_TIME" operator="eg, lt" value="2009-06-21T00, 2009-09-21T00">
summer
<txp:else />
<txp:smd_if field="svrvar:REQUEST_TIME, svrvar:REQUEST_TIME" operator="eg, lt" value="2009-09-21T00, 2009-12-21T00">
autumn
<txp:else />
<txp:smd_if field="svrvar:REQUEST_TIME, svrvar:REQUEST_TIME" operator="eg, lt" value="2009-12-21T00, 2010-03-21T00">
winter
<txp:else />
spring
</txp:smd_if>
</txp:smd_if>
</txp:smd_if>
All conditions return false, and I think I can see why: $_SERVER["REQUEST_TIME"]
is returning something like 1250452878
, so of course it will never match something like 2009-09-21T00
…
So I’m asking myself – well actually I’m asking anyone but myself of course ;)
- How (if at all) can I get this to work, using either another format or maybe another variable?
- If I can get this to work, is it possible to make it year-independent, so I don’t have to remember to change the values every year?
As I said I’ve already got it working using the txp variables, besides I’m aware that my questions are not exactly related to the plugin, so please don’t feel obliged to answer them.
Offline
#243 2009-08-16 21:52:21
Re: smd_if: Generic multiple if condition tests
<txp:php>
$seasons = array('1221' => 'winter', '0921' => 'autumn', '0621' => 'summer', '0321' => 'spring', '0000' => 'winter');
foreach($seasons as $date => $season) if (strftime('%m%e') >= $date) break;
echo $season;
</txp:php>
Offline
#244 2009-08-16 22:06:15
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: smd_if: Generic multiple if condition tests
Perfect! Thanks again :)
Sorry Stef, no need for the plugin after all…
Offline
#245 2009-08-17 07:44:39
Re: smd_if: Generic multiple if condition tests
Els wrote:
Sorry Stef, no need for the plugin after all…
Hehe, no worries. You can’t resist its charms forever ;-)
If you do ever get into this multi-condition scenario again and ruud isn’t at hand with an awesome bit of PHP to save the day, you could try smd_multi_choice which — if used cunningly — might have made the smd_if spaghetti slightly more manageable.
Last edited by Bloke (2009-08-17 07:45:39)
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
#246 2009-08-17 13:30:51
Re: smd_if: Generic multiple if condition tests
ruuds piece of code is a great example for a textpattern solution via code snippet.
Where do we store such TXP snippets?
I know the day will come where I want to publish all my winter activity recommendations in one article :)
Edit: For myself I found a pretty good solution for a structured repository lately: Zotero. I added an entry in my public Zotero group / Markus Merz / Textpattern (Detail).
Pls. have a look. If you want you may join ‘my’ group or we could create a public group ‘Textpattern’ (just to clutter the TXP environment a little more :)
Last edited by merz1 (2009-08-17 13:45:47)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
#247 2009-08-17 14:15:04
Re: smd_if: Generic multiple if condition tests
Btw, you may want to use safe_strftime instead of strftime to make it work properly in your timezone, unless it doesn’t really matter much if a season starts a few hours early or late.
Offline
#248 2009-08-17 15:38:57
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: smd_if: Generic multiple if condition tests
Bloke wrote:
you could try smd_multi_choice
Either I completely forgot about that, or I completely overlooked it… Looks sweet, I’ll keep it in mind for a next case!
ruud wrote:
Btw, you may want to use safe_strftime instead of strftime to make it work properly in your timezone, unless it doesn’t really matter much if a season starts a few hours early or late.
It doesn’t really matter in this particular case, but I’ll change it to safe_strftime anyway, thanks.
merz1 wrote:
Pls. have a look.
I will. At the moment I’m storing useful snippets, files etcetera about anywhere on my computer, without much structure…
Offline
#249 2009-08-18 21:07:02
Re: smd_if: Generic multiple if condition tests
[OT] At the moment I’m storing useful snippets, files etcetera about anywhere on my computer, without much structure…
That’s the good thing about Zotero. You store ‘etc.’ on your computer, add some metadata whenever you like and you may also publish the dataset to an open zotero group or not. Do you have webDAV server space? Yes, well, then add documents and have them synced with the webDAV server. Nice!
Last edited by merz1 (2009-08-18 21:07:59)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
#250 2009-08-20 10:25:15
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: smd_if: Generic multiple if condition tests
Stef,
I think I’m going mad. The following:
<txp:variable name="count" value="6" />
<txp:smd_if field="txpvar:count" operator="divisible" value="3">
<txp:variable name="count"/> is divisible by 3
<txp:else />
<txp:variable name="count"/> is not divisible by 3
</txp:smd_if>
gives me:
6 is not divisible by 3
What am I missing?
Cheers,
Adi
Offline
#251 2009-08-20 10:53:53
Re: smd_if: Generic multiple if condition tests
gomedia wrote:
I think I’m going mad.
And justifiably so if the plugin can’t count :-D
However, I tried it on my dev account in both an article form and directly in the article (in case it was Textile getting in the way) and both times received:
6 is divisible by 3
So something must be going squiffy somewhere along the line in your install. fwiw I’m using v0.8 of smd_if; are you? And what does adding debug="2"
(or 3) give you? Anything meaty that we can chew on to try and track this down?
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
#252 2009-08-20 11:10:05
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: smd_if: Generic multiple if condition tests
Panic over … Thought I was on 0.77, was actually on 0.74 but upgraded to 0.8 & it works perfectly. Just a minor insanity after all. Sorry for troubling you.
Adi
Offline