You are not logged in.
Bloke as always you are my hero….. thanks for the clarification!
Offline
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 ;)
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.
<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields
Offline
<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
Perfect! Thanks again :)
Sorry Stef, no need for the plugin after all…
<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields
Offline
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.
Txp Builders – finely-crafted code, design and Txp
Offline
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
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
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…
<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields
Offline
[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
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