If it could help you, I copy/paste a fragment of my widgetform
generator, I use it instead of text string for widget's template :
from formencode.htmlgen import html as T
back = T.form(name="f_"+self.key, action="save", method="post",
onsubmit="return validateForm(this)")(
T.div(id="f_" + self.key + "_errors_",
class_="formFieldErrors")(
T.span(py__if="not(f_" + self.key + "_errors_ is
None)", py__replace="str(f_" + self.key + "_errors_)")
),
...,
T.div(id="f_" + self.key + "_actions_",
class_="formActions")(
T.button(type="reset", id="btn_reset",
name="btn_reset")("reset"),
T.button(type="submit", id="btn_save",
name="btn_save")("save")
),
)
advantage : formencode is already part of TG
note the attribue py__if converted to html attribute py:if used by Kid