= [GenshiRecipes Genshi Recipes]: Automatically Populating an HTML Form = == Using match templates == The following template provides a match template that automatically adds a `value` attribute to any `` element that has matching data in the context. {{{ #!xml

Select one:

}}} Assuming the context data contained a variable “form” that was set to: {{{ #!python form = {'name': 'Look, Ma', 'enable': '', 'option': 'B', 'description': 'This is the description someone put in here', 'dropdown': '2'} }}} Then the output would look as follows: {{{ #!xml

Select one:

}}} == Using a template filter == The second, and maybe better, option, would be to use a custom template filter that filled in the form values. An example is [attachment:formfiller.py attached] to this page, and would be used like this: {{{ #!python tmpl = loader.load('myform.html') fill = HTMLFormFiller({ 'name': 'Look, Ma', 'enable': 'on', 'option': 'B', 'description': 'This is the description someone put in here', 'dropdown': '2' }) print tmpl.generate().filter(fill).render('xhtml') }}} That would result in the same output as above. '''Note''': the `HTMLFormFiller` class is available in the `genshi.filters` module starting from [milestone:0.4] release. ---- See also: GenshiRecipes, [wiki:Documentation/xml-templates.html Genshi XML Template Language]