From: Marc P. <ma...@an...> - 2003-07-28 14:21:50
|
Guys, Following on from the discussion with Keats a few days ago, to solve the problem of calling snippets of WM script without having a huge #if...#elseif chain or using #include, I have added a "get" method to VariableTool. Usage is trivial, but very useful: #templet $templateA This is A! #end #templet $templateB This is B! #end #set $items = [ "A", "A", "B", "B", "B", "A"] #foreach $i in $items #eval $Variable.get("template$i") #end This outputs: This is A! This is A! This is B! This is B! This is B! This is A! This is very nice indeed for iterating over lists of objects and doing different things based on a value of a property of the objects. This could also be used as function of course, making it even more convenient. Can I commit? It's trivial: /** * Get the specified object <code>name</code> defined from the active * Context. */ public Object get (Object name) { return context.get(name); } 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 |