if that variable [page] not in globals - error raised if [page] is setted - all work
среда, 24 июня 2015 г., 15:42:56 UTC+3 пользователь Anthony написал: > > {{include}} and {{extend}} are template directives, not Python code. So, > even if the Python "if" statement evaluates to False, the {{include page}} > will still remain in the template and get executed (though once the actual > template code is included there, *that *code will not be executed). So, > instead, you have to do something like: > > {{if 'include_page' in globals():}} > {{include 'page.html'}} > ... > > There is a simpler approach (though I'm not sure it is documented): > > {{include page if 'page' in globals() else None}} > > The advantage of this approach is that it does not actually include and > parse the "page" template when the condition is False, so it should be > faster in that case. The above also works with {{extend}}: > > {{extend 'my_layout.html' if some_condition else None}} > > Anthony > > On Wednesday, June 24, 2015 at 2:43:21 AM UTC-4, Dmitry Ermolaev wrote: >> >> {{if 'page' in globals():}} >> {{include page}} >> {{else:}} >> {{=list}} >> {{pass}} >> >> erro - >> >> File "C:\web2py-m\gluon\template.py", line 684, in parse >> self.include(top, value) >> File "C:\web2py-m\gluon\template.py", line 462, in include >> text = self._get_file_text(filename) >> File "C:\web2py-m\gluon\template.py", line 439, in _get_file_text >> filename = eval(filename, context) >> File "<string>", line 1, in <module> >> NameError: name 'page' is not defined >> >> >> OR how include HTML file in controller? >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.