You are not logged in.
Thanks Stef!
it was the line break problem.
Great plugin!!! helping a lot on this realestate website I am making!
Offline
Hiya Stef,
I have the following code:
<txp:smd_if field="urlvar:day" operator="gt:NUM, lt:NUM" value="0, 32">
<txp:smd_if field="urlvar:month" operator="gt:NUM, lt:NUM" value="0, 13">
something fantastic happens here!
</txp:smd_if>
</txp:smd_if>
and was wondering whether it would be possible to create a new operator called bn (to stand for “between”) where the numerical values to compare could be separated by “|”? The above code could then be written as below:
<txp:smd_if field="urlvar:day, urlvar:month" operator="bn:NUM, bn:NUM" value="0|32, 0|13">
something fantastic happens here!
</txp:smd_if>
What say you, kind Sir?
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
speeke wrote:
create a new operator called
bn(to stand for “between”) where the numerical values to compare could be separated by “|”?
A noble request. Leave it with me and I’ll see if the plugin can be beaten into this shape for you.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Done :-)
Two new operators for your comfort and enjoyment:
between for testing if the given values lie (exclusively) between the values you giverange is exactly the same but includes the end points as valid valuesIn other words, between uses > and <, whereas range uses >= and <= (the :NUM is optional for most cases). Note that you use the list_delim attribute between values, e.g. value="0/32".
See example 10 in the help for an embodiment of your post above. As always, let me know how y’all get on with this version.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Brilliant Stef!
Shall take it for a whirl and let you know how it goes. Thanks so much :-)
BTW: Your mention of 31st February in Example 10 has given me a bit more to think about, like 31st September/April/June/November! However, in my case, I will be testing user input for day, month and year as it relates to the user’s date of birth. I guess if someone wants to record their birthday as 31 September 2011, then good luck to them ;-)
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
Just tested the following:
<txp:php>
global $thisyear;
$thisyear = date("Y");
</txp:php>
<txp:smd_if field="urlvar:d, urlvar:m, urlvar:y" operator="range, range, range" value="1/31, 1/12, 1900/phpvar:thisyear">
blah, blah, blah
</txp:smd_if>
All works like a charm, except the global variable $thisyear – which worked with the previous version of the plugin. I’m guessing the list_delim attribute is causing confusion???
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
speeke wrote:
except the global variable
$thisyear
Bugger, more thought required. All our lines are currently busy but your call is important to us. Please hold and an operator will be with you shortly…
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Sheesh, that was harder than I expected. After much fiddling and large-scale internal code refactorisation, smd_if is back with a brand new pig bag
From your perspective, there’s nothing new in this version except that you now have the capability to specify more than one field inside values. For example:
<txp:smd_if field="urlvar:tester" operator="in" value="1/3/7/?custom1/13/txpvar:some_val/19">
// tester matches one of the values
</txp:smd_if>
In previous versions that would fail, but the plugin now correctly inserts each value — or sub-list of values! — in place of its variable and then the whole list is compared with the field. This works using operators in, notin, between and range. You’ll also get a whole load more replacement tags with these operators — one for each value in your list. That gives you more flexibility about what to display inside your container.
Because of the big changes inside the plugin I’ve bumped the major version number. This version should however be backwards compatible with previous versions; please let me know if I’ve missed anything or broken any previous smd_if magic.
Above all, enjoy.
Last edited by Bloke (2010-03-02 23:17:29)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Bloke wrote:
After much fiddling and large-scale internal code refactorisation, smd_if is back with a brand new pig bag.
Thanks, Mr Incredible!
please let me know if I’ve missed anything or broken any previous smd_if magic.
Will do.
Above all, enjoy.
Absolutely … as always ;-)
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline
OK, so I have the thrown together the code below to check for invalid date combos (following on from your note in Example 10):
<txp:smd_if field="urlvar:d, urlvar:m" operator="eq, in" value="31, 2/4/6/9/11">
<txp:variable name="datetest" value="0" />
</txp:smd_if>
<txp:smd_if field="urlvar:d, urlvar:m" operator="eq, eq" value="30, 2">
<txp:variable name="datetest" value="0" />
</txp:smd_if>
<txp:smd_if field="urlvar:d, urlvar:m, phpvar:leaptest" operator="eq, eq, not" value="29, 2, 1">
<txp:variable name="datetest" value="0" />
</txp:smd_if>
The first smd_if checks for months that don’t have day 31, the next checks for months that don’t have day 30 (Feb), and the last checks 29 Feb for leap years (the php variable leaptest is set to 1 if it is a leap year).
I tried placing the php function that tests for a leap year in the smd_if field, but it spat the dummy.
The TxP variable datetest is used to determine if an error message should be shown.
So this is the “prettiest” approach I could come up with. Am I using the plugin in the best possible configuration here?
“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower
Offline