Reusable HTML snippets and sub-views in web2py
Asked Answered
C

1

6

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?
Charitacharitable answered 15/12, 2011 at 14:41 Comment(0)
H
5
  • 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).

Humidity answered 15/12, 2011 at 21:15 Comment(1)
Wow- completely overlooked that feature- thought you could only use {{include}} for extending, not nesting. Thank you! (It's talked about here)Charitacharitable

© 2022 - 2024 — McMap. All rights reserved.