On 20/04/2006, at 21:13, Jonathan LaCour wrote:
> I haven't been able to keep up with all the widget changes, and I am
> starting to use them again for a new project.  I am needing to have a
> default value in a widget that can be changed as a parameter to
> display() or render().  I thought I could do the following:
>
>     class MyWidget(Widget):
>         template = 'my.template.for.the.widget'
>         template_vars = ['defaulted_param']
>         defaulted_param = False
>
>     mywidget = MyWidget()
>
> ... and then when I used it, I could just do a `mywidget.display()'
> and it would assume a value of False for defaulted_param, but I can
> override this with `mywidget.display(defaulted_param=True)'.
>
> Is this still the case?  It doesn't seem to be working for me, or I
> am misunderstanding widgets (again).  I really can't wait for the
> documentation sprint to be over, so I can finally fully grasp  
> widgets ;)

Yes, it should still the be case:

 >>> from turbogears.widgets import Widget
 >>> class MyWidget(Widget):
...     template = """<div xmlns:py="http://purl.org/kid/ns#";><span  
py:if="test_param">True</span><span py:if="not test_param">False</ 
span></div>"""
...     params = ["test_param"]
...     test_param = False
...
 >>> w = MyWidget()
 >>> w.render()
'<DIV><SPAN>False</SPAN></DIV>'
 >>> w.render(test_param=True)
'<DIV><SPAN>True</SPAN></DIV>'
 >>>

Can you post the example where it's not working for you? Maybe you're  
still using the deprecated template_vars and the code that's handling  
the deprecation is faullty, or there is a big, or, hopdully, just  
misuse... :)

There are some new docstrings in the trunk hoping to aid in the lack  
of widget docs, it's not a substitute for real docs but a start...

Alberto

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to