Skip to content

Base template $if content.somevar does not work as documented #199

Open
drjayvee opened this Issue Dec 21, 2012 · 0 comments

1 participant

@drjayvee

According to the cook book, a site layout template can use $if content.somevar.

However, I get

<type 'exceptions.AttributeError'> at /
'somevar'

I've tried this suggestion from a (rather old) Google Groups post:

$if hasattr(content, 'somevar')

But that results in

<type 'exceptions.NameError'> at /
global name 'hasattr' is not defined

I thought this might be a problem with security, but the doc says a SecurityException should be thrown in that case. If I change the code to use getattr (which is explicitly mentioned as forbidden in the docs), I get the same error (does that mean that the docs are off, and no SecurityException is thrown?).

Now, as a workaround, you can of course write $var somevar: in the page template, but that completely defeats the purpose of $if content.somevar in the base template, as you could just print $content.somevar if it's never unset.

By the way:

>>> import web
>>> web.__version__
'0.37'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.