Velocimacro – Generate a HTML Select box and its Options

A quick and simple Velocimacro to generate HTML Select boxes and its Options; automatically selects the correct option based on the value given.
You can place this #macro anywhere in your Velocity templates but I used my global VM_global_library.vm file.
Code
[code]
#macro( generateSelectBox $name $options $value )

#end
[/code]
Example Usage
[code]
#generateSelectBox( “enabled” [“Y”,”N”] $form.enabled )
[/code]
The resulting HTML:
[code]

[/code]
Addendum
11th November 2005 : Thanks to MATT for pointing out the FreeMarker template engine as a promising replacement for Velocity. 😉


Comments

One response to “Velocimacro – Generate a HTML Select box and its Options”

  1. But why use Velocity when you could use Freemarker?? ;-p

Leave a Reply

Your email address will not be published. Required fields are marked *