Are you calling 'config.scan()' to pick up the subscriber?
If you aren't, then you need to, or use config.add_subscriber(add_global,
BeforeRender).

Michael


On Sat, Apr 16, 2011 at 4:04 PM, AwaisMuzaffar <[email protected]>wrote:

>
> Thanks for the reply.
>
> Not sure why I get a NameError("Undefined") when doing that.
>
> My view is like this:
>
> @subscriber(BeforeRender)
> def add_global(event):
>     event['abc'] = 'foo'
>
> def home_view(request):
>    return render_to_response('myblog:templates/pages/home.mak',
> {'name': 'Pyramid Developer'}, request=request)
>
> and in the template when I do:
>
> ${abc}
>
> I get:
>
> URL: http://127.0.0.1:6543/
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/
> WebError-0.10.3-py2.6.egg/weberror/evalexception.py', line 431 in
> respond
>  app_iter = self.application(environ, detect_start_response)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/
> repoze.tm2-1.0b1-py2.6.egg/repoze/tm/__init__.py', line 23 in __call__
>  result = self.application(environ, save_status_and_headers)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/router.py', line 158 in __call__
>  response = view_callable(context, request)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/config.py', line 2916 in _requestonly_view
>  response = view(request)
> File '/Users/Awais/virtualenv/MyBlog/myblog/views.py', line 49 in
> home_view
>  return render_to_response('myblog:templates/pages/home.mak',
> {'name': 'Pyramid Developer'}, request=request)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/renderers.py', line 111 in render_to_response
>  return helper.render_to_response(value, None, request=request)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/renderers.py', line 322 in render_to_response
>  result = self.render(value, system_values, request=request)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/renderers.py', line 318 in render
>  result = renderer(value, system_values)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/pyramid-1.0-
> py2.6.egg/pyramid/mako_templating.py', line 131 in __call__
>  result = template.render_unicode(**system)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/Mako-0.3.6-
> py2.6.egg/mako/template.py', line 292 in render_unicode
>  as_unicode=True)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/Mako-0.3.6-
> py2.6.egg/mako/runtime.py', line 575 in _render
>  **_kwargs_for_callable(callable_, data))
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/Mako-0.3.6-
> py2.6.egg/mako/runtime.py', line 607 in _render_context
>  _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/Mako-0.3.6-
> py2.6.egg/mako/runtime.py', line 633 in _exec_template
>  callable_(context, *args, **kwargs)
> File 'myblog_templates_pages____base_mak', line 25 in render_body
> File 'myblog_templates_pages_home_mak', line 38 in render_body
> File '/Users/Awais/virtualenv/lib/python2.6/site-packages/Mako-0.3.6-
> py2.6.egg/mako/runtime.py', line 181 in __str__
>  raise NameError("Undefined")
> NameError: Undefined
>
>
>
> On Apr 16, 8:21 pm, Chris McDonough <[email protected]> wrote:
> > 'mykey' will be available "magically" as a top-level name in the
> template.  Just use it.
> >
> > On Apr 16, 2011, at 2:19 PM, AwaisMuzaffar <[email protected]>
> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hi Guys,
> >
> > > When I use the before render event like so:
> >
> > > from pyramid.events import subscriber
> > > from pyramid.events import BeforeRender
> >
> > > @subscriber(BeforeRender)
> > > def add_global(event):
> > >     event['mykey'] = 'foo'
> >
> > > How exactly do I call these variables my templates. I can't seem to
> > > find this out from the documentation.
> >
> > > --
> > > 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 athttp://
> 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.
>
>

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

Reply via email to