Reputation: 33
I need to specify an attribute for the body-tag as follows:
<body onresize="window.location.href=window.location.href">
Of course I can do this in the corresponding view. But then I have two opening body-tags in the resulting HTML code. The HTML code works, but is not compliant to given standards.
Thus, my question is, if there is a way to specify the attribute, that it is included in the generated response body-tag.
Thanks for any support!
Upvotes: 0
Views: 54
Reputation: 25536
In the "layout.html" view, you can do something like this:
<body{{=XML(' onresize="window.location.href=window.location.href"') if response.resizable_body else ''}}>
Then in a model or controller, you can do:
response.resizable_body = True
Or in a view (note, the resizable_body
attribute is set before extending the layout):
{{response.resizable_body = True}}
{{extend 'layout.html'}}
There is no need to explicitly set response.resizable_body
to False
at any point, as response.resizable_body
will simply be None
by default (response
is a Storage
object, so when you attempt to access a non-existent attribute, it simply yields None
).
Upvotes: 1
Reputation: 33
Okay, I've found the solution ... it's all easy when you think ;-)
Since the body-tag derives from extending "layout.html" {{extend 'layout.html'}} one can change the body-tag there. If there is the need not to have the onresize attribute for all views, one can have an adaption of "layout.html" for example "layout-onresize.html" for this special purpose.
Upvotes: 0