Reusable HTML snippets and subviews in web2py

I have some reusable HTML snippets that I want to include in several web2py views.

Using components with LOAD means having to write down individual controller functions that must load their own data.

Is there any way:

  • Reusing dumb (no data) html fragments in views?
  • Reuse of the submenu that inherits the variables of the parent view so that they can be inserted without calling the controller functions and reloading the data?
+6
source share
1 answer
  • Reusing dumb (no data) html fragments in views?

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

 {{include 'snippets/my_snippet.html'}} 
  • Reuse of the submenu that inherits the variables of the parent view so that they can be inserted without calling the controller functions and reloading the data?

The above considerations will have access to the variables returned by the controller, and to any variables defined in the parent view before inclusion (as well as global variables defined in the models, like any view).

+5
source

Source: https://habr.com/ru/post/903849/


All Articles