[web2py] Re: conditionally include in view
correct On Mar 9, 5:14 pm, ron_m ron.mco...@gmail.com wrote: I use this in a portion of the views coded for what I am working on and it works for me. I just ran the page with the test true and again with the test false and I get the include file content inside the {{if condition:}} branch if the condition is True and the html in the {{else:} branch if the condition is False. I verified with a View Source in the browser, the code from the include file is not there when the condition is False. I am on 1.93.2 but this has been consistent for several months now. Here is a chunk of code {{site_names = session.user_access['site_names']}} {{if len(site_names) 1:}} {{include 'common/site_switcher.html'}} hr / {{else:}} {{=B(header)}} {{pass}} {{include 'live/display_mode_switcher.html'}} hr/ I think the include is indeed expanded out unconditionally but when the Python logic runs the response.write is not executed for that portion of the code if condition is False. Replace someData in your example with True and then with False and refresh the page to see what you get in each case. The truthness or falseness of a variable can be deceiving. Also the include file name should be the path portion past views.
[web2py] Re: conditionally include in view
Include is executed whether or not the condition is true. It is not python code therefore it is executed before the python code is executed. It is not a good idea to put the include in a condition. On Mar 9, 12:24 pm, m t monsun...@gmail.com wrote: Hi, I have such code: {{if someData:}} {{include 'additional.html'}} {{pass}} problem is that even when 'someData' is NOT true - file 'additional.html' is included. Is there some trick to select on view level which includes shall be loaded?
[web2py] Re: conditionally include in view
I use this in a portion of the views coded for what I am working on and it works for me. I just ran the page with the test true and again with the test false and I get the include file content inside the {{if condition:}} branch if the condition is True and the html in the {{else:} branch if the condition is False. I verified with a View Source in the browser, the code from the include file is not there when the condition is False. I am on 1.93.2 but this has been consistent for several months now. Here is a chunk of code {{site_names = session.user_access['site_names']}} {{if len(site_names) 1:}} {{include 'common/site_switcher.html'}} hr / {{else:}} {{=B(header)}} {{pass}} {{include 'live/display_mode_switcher.html'}} hr/ I think the include is indeed expanded out unconditionally but when the Python logic runs the response.write is not executed for that portion of the code if condition is False. Replace someData in your example with True and then with False and refresh the page to see what you get in each case. The truthness or falseness of a variable can be deceiving. Also the include file name should be the path portion past views.