If you define it in a model file, it will be available in all views. You 
could also define it in its own view file and then include that view file 
in either your layout.html or in your individual views for specific actions.

Anthony

On Thursday, December 22, 2011 8:12:50 AM UTC-5, greenguerilla wrote:
>
> Hi, 
>
> I have a search form which I wish to appear on every page. I would 
> rather define this programatically than with html but I wish to avoid 
> having to remember to add this variable to the dictionary returned by 
> every controller function. 
>
> In Django one can create a context processor which returns the 
> variable and use a RequestContext in every view function. Is there a 
> similar mechanism for web2py? If the answer is to store it in the 
> response object, is there a place where I can write this code once and 
> once only and have it added automatically to the response every time? 
>
> Another option I considered was to define a custom dictionary: 
> my_dict = dict(search_form=search_form) 
>
> Then I could update this in every controller function and return it. 
> That would still require modifying all of our controller functions 
> though... 
>
> Any and all suggestions are welcome! 
>
> Cheers, 
>
> John

Reply via email to