From: Lane S. <la...@op...> - 2003-07-23 17:26:41
|
Marc Palmer wrote: > > 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 problem has been solved. Use SparseProperties as a wrapper around fields which may or may not be null and for which you do not want to test for nullness. Use it all the time in my WM processing and it elegantly solves the problems: Optional Values:<br> $Render($Schema.FirstName)<br> $Render($Schema.LastName)<br> If FirstName and LastName are not found in the map, you can have the instance of SparseProperties return "", null, "Not Defined" or whatever you like. > > > 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"> Using sparse properties: <input name="x" value="$Values.x"> will return the value of x if it is not null or "Enter a Value" if that is the default for a null value. Check out this helper, Marc. -Lane > > > 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 > |