You could define some_function in a model file (functions defined in model files are available in views, though functions defined in controllers are not), and then you could call it directly in your layout.html view (or you could call it within a separate sidebar view file, and then include that sidebar view in layout.html). For example: {{=some_function()['rows']}} Another option would be to include a component in your sidebar (see http://web2py.com/book/default/chapter/13#Components), either with or without using Ajax. For example: {{=LOAD(f='some_function', ajax=False)}} Anthony On Friday, April 1, 2011 11:25:29 PM UTC-4, kawate wrote:
> hello everybody, > > i like to display database records in sidebar of every page. > i define the function that fetch the records and return as dictionary. > then i put the function in default.py and return the result of the > function every view function, it works fine. > such as, > def some_function(): > ''fetch database records'' > return rows > def index(): > rows = some_function() > return dict(rows=rows) > > in layout.html: > {{for row in rows:}} > <li>{{=row}}</li> > {{pass}} > > But this approach is awkward. i like to hide sidebar rendering from > main page rendering. > There should be more beautiful approach in web2py. > Is there any ideas? > > Thank you in advance. > > > >