Sunday, April 25, 2010

Little tip of Mako template

    “selected” is always used to indicate selected state of option in SELECT HTML component. So it’s useful to write “selected” in one line as its option tag. Following code will generate this:

<%def name="optionselected(x)"><%if x: __M_writer(u"selected")%></%def>

<option value="python" ${optionselected(c.id == "python")}></option>

1 comment: