Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusable HTML snippets and sub-views in web2py

I have some reusable HTML snippets that I want to 'include' in a number of web2py views.

Using components with LOAD means having to write separate controller functions which need to load their own data.

Is there a way to:

  • Reuse dumb (no data) html snippets across views?
  • Reuse sub-views that would inherit the variables of the parent view, so that they can be inserted without calling controller functions and reloading data?
like image 238
Yarin Avatar asked Dec 15 '11 14:12

Yarin


1 Answers

  • Reuse dumb (no data) html snippets across views?

You can use the {{include}} directive to include any view inside any other view. If you have /views/snippets/my_snippet.html, just do:

{{include 'snippets/my_snippet.html'}}
  • Reuse sub-views that would inherit the variables of the parent view, so that they can be inserted without calling controller functions and reloading data?

Views included as above will have access to the variables returned by the controller and any variables defined in the parent view prior to the include (as well as global variables defined in the models, just like any view).

like image 114
Anthony Avatar answered Nov 14 '22 18:11

Anthony