= [GenshiRecipes Genshi Recipes]: Automatically Populating an HTML Form = The goal is to automatically add a `value` attribute to any `` element with the appropriate data, and similar for other kinds of form controls. Assume the following template defining a simple form: {{{ #!genshi
}}} == Using a Stream Flter == The best option is to use the Genshi [wiki:Documentation/filters.html#html-form-filler HTMLFormFiller] stream filter that fills in form values. {{{ #!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('html') }}} The output would look as follows: {{{ #!text/html }}} == 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. {{{ #!genshi … … }}} 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'} }}} That would result in the same (or similar) output as above. ---- See also: GenshiRecipes, [wiki:Documentation/xml-templates.html Genshi XML Template Language]