You are not logged in.
if_this / if_that plugins and tags are great, but sometimes you just need that tiny bit more. Like what if this AND that are true? Nesting of tags is possible, but can become unwieldy with many <txp:else /> clauses.
May I present smd_if as an alternative approach.
Give it a list of virtually any Txp variables, some conditional operators like equals, not, greater than, begins with, contains, defined, etc, and some values to check against and it’ll compare them all. Only if they all match will it do what you ask. It can also use ‘or’ logic to specify that the condition is met if any one of the values match.
Compatible with <txp:else /> and also supports <txp:variable />, URL variables (e.g. only display something if pg > 1?) and server variables (e.g. only display something if the user’s IP address matches something?). The docs explain more
It’s ugly, it’s downright dirty… but it can sometimes get you out of a hole. Use it, abuse it and report any enhancements, ideas, bugs, etc here. Happy New Year to everyone :-)
Revision history
————————
All available versions and changes are listed here. Each entry indexes the relevant post(s) in this thread to learn about the features.
? notation to allow the value to read Txp fields. Better quote support (both thanks NeilA)is operators, the ends operator, more pretext variables and file / link supportin, notin and the list_delim attribute; enabled replacement tags for matched variables:NOTAGS (thanks mapu):NOSPACE to begins, ends and contains (thanks mapu), added phpvar support, :LEN modifier and length replacement tags (all thanks the_ghost)field attribute (thanks redbot)postvar field type (thanks kostas45):TRIM modifier (thanks gomedia)TTL and KIDS modifiers (thanks photonomad) ; improved parent debug outputvar_prefix to allow nesting of smd_if tags; added :COUNT modifier (thanks the_ghost) ; added :ESC and :ESCALL modifiers (thanks lazlo); fixed checks for defined / undefinedLast edited by Bloke (2012-01-28 01:15:30)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Just add checking parent category name and it will be the only conditional plugin in my install :)
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
the_ghost wrote:
Just add checking parent category name and it will be the only conditional plugin in my install :)
Hehe, hadn’t thought of that. I’ll see what I can do. Mind you, I’m not sure how efficient the plugin is with the eval() calls it does. It may be better to reserve this plugin only for use when you absolutely have to; conventional if_something tags may well be less drain on TXP (just guessing). This is, however, certainly quite a good replacement for a few ‘if’ plugins, and chs_if_urlvar which has a few compatibility issues (TXP warnings) and doesn’t support <txp:else />.
Anyway, when you say “parent” do you mean just check one level ‘up’ the tree or do you mean “is the current category a member of this given parent category at any level”?
EDIT: oh, and do you mean the parent of the current ‘global’ category (?c=) or category1 / category2?
Last edited by Bloke (2007-12-30 18:34:02)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
OK, I went ahead anyway and did it all. Global category, category 1/2 and/or checking of a particular sub-category at any level.
Try v0.2 and see if it meets your needs.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Mr Bloke, this is mega.
Offline
Major code overhaul (internally) but functionally you shouldn’t spot anything massively different. Mis-spelled variables are now all assumed to be part of the $thisarticle array and will thus return “empty”. Some didn’t do that in earlier versions.
Added two new operator tests: defined and undefined. They differ semantically from isused and isempty (respectively), but the way TXP assigns variables means that, for the most part, they are interchangeable. One caveat is that defined and undefined don’t make sense with parent, so they are forbidden.
Also added a feature to the gt, lt, le and ge operators. You can now specify :NUM on the end of these operators to force the comparison to be integer. This bypasses the problem that the number “5” is technically “less than” the word “squid” when both are treated as strings.
v0.3 is the official release. Share and Enjoy TM
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
hm… What about adding checking if we have search results? :)
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Oh my god, you’ve saved my sanity. Thank you for this most beautiful and flexible plugin,
Peter
Offline