From: Marc P. <ma...@an...> - 2003-07-23 17:03:39
|
If you're wondering why I'm bombarding the list so much at the moment (apologies) it's because I'm working on a real-life web site now that uses Ignition. Wading through the complexitis of metadata/schema based data capture, with most of the problems solved by Ignition, in some places I'm encountering / getting bored with the same old "is it null or not before I evaluate it" problem. This has probably been mentioned before, but what about something like: #safe $myVar Whatever you want to call #safe... but the idea is it will only evaluate the variable if it is not null. If it is null, it will do nothing. Diddly squat. You could - and this is probably stupid - extend it with an #else sub-directive, so it is mereley an abbreviated form of #if: #safe $myVar #else You have not set the variable! #end The advantage here over #if is that you don't need to specify a block for the "not null" case because the variable is your output. The other alternative is a trivial function: $safe($myVar, "You have not set the variable!") Which is functionally identical. This second form is a bit nicer in usage because you don't have the whitespace "nuances" we've discussed with directives. However I like the directive syntax better if there wasn't the whitespace hassle: <input name="x" value="#safe $valueOfX #else Enter a Value #end"> If something like this isn't already in the distro we should definitely add it. It doesn't solve all of the problems, but it would sure make some templates more readable and less boring to maintain! I'm happy to write this (yes of course it's trivial) and commit it if people think this is worthy of WM core/options status. Marc -- Marc Palmer Contract Java Consultant/Developer w a n g j a m m e r s java and web software design experts with an ethical outlook http://www.wangjammers.org |