Thanks Chris, that worked great!

Here's my new class:

class MyTableForm(widgets.TableForm):
    params = ['extra_template_vars']
    extra_template_vars = {}

    def update_params(self, params):
        params.update(params.get('extra_template_vars', {}))
        super(MyTableForm, self).update_params(params)

Updated controller code:

http://paste.turbogears.org/paste/5592

I may move the form instantiation out of the controller now also.

Cheers,

Steve


On Aug 30, 10:14 am, Christopher Arndt <[EMAIL PROTECTED]> wrote:
> Hi,
>
> shday schrieb:
>
> > I'd like to be able to access arbitrary template variables (passed
> > from the controller) from within my custom form template.
>
> Accessing arbitrary template values in widget templates is not possible,
> IMHO, but you can provide selected values from the template to your widgets.
>
> > Is there a way to access "site" from a custom form template? What
> > about accessing "values" directly?
>
> > What am I trying to do? I'm trying to change the look of a form based
> > on the value of "site". My work-around is to use separate templates:
>
> Make a form widgets subclass that accepts an additional parameter, e.g.
> "extra_template_vars" and then when you display the widget in the
> template do:
>
> ${form.display(value, extra_template_vars=dict(site=site, foo=bar, ..))}
>
> Then in the form widget class provide an "update_params" method like
> this (untested):
>
> class MyFormWidget(widgets.Form):
>     params = ['extra_template_vars']
>     extra_template_vars = {}
>
>     def update_params(self, params):
>         params.update(params.get('extra_template_vars', {})
>         super(MyFormWidget, self).update_params(params)
>
> HTH, Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to