You know what. I see now that it's my thinking thats wrong. But. I think Jinja2 is also doing it wrong.
As suggested by inklesspen in #pylons - Jinja2, instead of catching the ArgumentException, silencing it, and returning 'jinja2.runtime.Undefined', should just let the ArgumentException fire. Then the user knows straight away there is a problem and can fix their code :) On Jul 25, 7:12 pm, "The Devil's Programmer" <[email protected]> wrote: > Giving an example... > > I set 'c.category = None' in my controller to indicate to the template > that no category is being browsed at present. > > Then in my template I have a line like this: > > {{ url(controller='browse', action='article_browser', > section='popular', category_slug=c.category.slug, page=pages.next) }} > > Jinja2 trys to access 'c.category.slug', it can't, because > 'c.category' is set to None, and so it returns a class of the type > 'jinja2.runtime.Undefined' > > What I am suggesting is that returning the Undefined class is > pointless. It should instead just return None. What good is it to me > to have an Undefined class? What can I do with it? Why would I need > it? > > You might suggest that I use an if statement. That is not feasable. > The code I have shown you is just an example of the problem. My code > is far more complex, and makes many calls to url() with reference to > 'c.category.category_slug', and putting if statements over the place > would just mess things up. > > Hope that makes more sense. > > On Jul 25, 5:13 pm, "The Devil's Programmer" > > <[email protected]> wrote: > > I'm using pylons, and when I access a value from the context which has > > not been defined, instead of returning None like you'd expect it to, > > it returns a class of type 'jinja2.runtime.Undefined' > > > It's screwing up my url generation, because when I try to generate a > > url with category=c.category, and category is set to None (ie..user > > not currently browsing a specific category), it tries to match a url > > with category=Undefined. > > > I see no reason for this behavior. When would that Undefined class > > ever be useful to the template? > > > And yes, > > config['pylons.strict_c'] = True > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pocoo-libs" 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/pocoo-libs?hl=en -~----------~----~----~----~------~----~------~--~---
