Malthe's solution is the simplest and it works perfectly. But thank you all for your answers!
- Theron On Thu, May 10, 2012 at 9:48 AM, Raj <[email protected]> wrote: > In the second example, config.scan() finds your @subscriber(BeforeRender) > > > On Thursday, May 10, 2012 12:46:22 PM UTC-4, Raj wrote: >> >> You can create an 'h' helper object as described here--> http://docs.** >> pylonsproject.org/projects/**pyramid_cookbook/en/latest/** >> templates/templates.html#**using-a-before-render-event-** >> to-expose-an-h-helper-object<http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/templates/templates.html#using-a-before-render-event-to-expose-an-h-helper-object> >> >> or just have a subscribers.py file with: >> >> @subscriber(BeforeRender) >> def template_globals(event): >> request = event['request'] ## this is how you access the request >> object in this function >> >> from datetime import datetime >> event.update({'someglobalvar': 'this is my global value', >> 'thedate': datetime.now}) >> >> return ##no need to return anything >> >> >> Then you can just do ${thedate()} in any of your templates. >> -Raj >> >> >> On Wednesday, May 9, 2012 12:27:14 AM UTC-4, Theron Luhn wrote: >>> >>> I can pass variables into my template by returning them in a dictionary >>> from the view controller. However, if I try to access a variable from the >>> template that I didn't pass, I'll get an error. Is it possible to have a >>> default value so I don't get an error? Maybe with BeforeRender or something? >>> >>> - Theron >>> >> -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/pylons-discuss/-/Uw-XGOu0ppcJ. > > 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/pylons-discuss?hl=en. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
