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
If you are using mako, you may want to have a look at
http://docs.makotemplates.org/en/latest/runtime.html#context-variables
and adapt the strict_undefined setting in your config.
regards
robert
On Wed, May 9, 2012 at 6:27 AM, Theron Luhn <the...@luhn.com> 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 post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscribe@googlegroups.com.
@subscriber(BeforeRender)def template_globals(event):request = event['request'] ## this is how you access the request object in this functionfrom datetime import datetimeevent.update({'someglobalvar': 'this is my global value','thedate': datetime.now})return ##no need to return anything
--
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 pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.