On Saturday, December 22, 2012 5:00:52 PM UTC-5, jonas wrote:
> Ok, I have a {{include}} statement in the beginning of the layout.html
> file that cals index.html and the corresponding index.py controller. And
> that one returns variables. So there is no way to call sidebar.py with tve
> corresponding view to get the variables?
>
That's not quite how it works. Views do not call controllers. Rather, when
a URL is requested, web2py routes the request to a particular controller.
Once the controller returns, then the view is executed. So, your browser
calls /myapp/default/index. web2py receives that request, and after
executing your model files, it runs the index() function in the default.py
controller. After the index() function returns, it then executes the
/views/default/index.html view (with the keys/values of the dict returned
by the index() function being available as variables within the view). Your
index.html view then extends the layout.html view, which means its code
gets inserted in place of the {{include}} within layout.html. So, the
{{include}} in layout.html is not calling index.html, and index.html is not
calling the index() function -- the order is the exact opposite -- the
index() function is called first, then the index.html view is executed, and
finally the index.html view extends layout.html.
Anthony
--