ok, to include everything in the for loop is more elegant. The reason
why I wanted to separate the call to sidebar.py is that the sidebar
contains almost static material that doesn't change that much, while
the main page (index page) has content that changes more. In the first
version I had the db variable defined in the index.py controller. I
Think this is a common situation, sidebar content that doesn't change
much and a main part that is updated more frequently so some sort of
content separation is preferable.
The solution to put it in the view instead is ok for me.

On Mon, Dec 24, 2012 at 2:09 AM, Anthony <[email protected]> wrote:
>> <h4><i class="icon-user"></i> me (from sidebar.html):</h4>
>>
>> {{query=db.about.id>0}}
>> {{ab=db(query).select()}}
>> {{dict(ab=ab)}}
>
>
> The dict line above isn't necessary. The controller function returns a dict
> so that the dict's keys will be added as global variables in the view
> environment, but since you're already in the view here, simply defining the
> ab variable is sufficient.
>
>>
>> {{for pre in ab:}}
>
>
> Actually, you might as well just do this:
>
> {{for pre in db(db.about).select():}}
>
>>
>> but it would have been better to return the ab dict from the sidebar.py
>> controller instead.
>
>
> If you really want the sidebar created by its own controller function and
> view, you can use a component (i.e., the LOAD helper), though in this case
> that would probably generate an unnecessary amount of extra processing for
> something rather simple. If you don't want to run the query in the view but
> need the sidebar on every page, then you can simply define the ab variable
> in a model file (all variables defined in model files are available globally
> in all views).
>
> It might also be a good idea to cache the query for some amount of time to
> avoid a separate database hit on every page request.
>
> Anthony
>
> --
>
>
>

-- 



Reply via email to