web2py 中可重用的 HTML 片段和子视图
我有一些可重用的 HTML 片段,我想将它们“包含”在许多 web2py 视图中。
使用具有 LOAD 的组件意味着必须编写需要加载自己的数据的单独控制器函数。
有没有办法:
- 跨视图重用哑(无数据)html 片段?
- 重用继承父视图变量的子视图,以便可以在不调用控制器函数和重新加载数据的情况下插入它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
{{include}}
指令将任何视图包含在任何其他视图中。如果您有 /views/snippets/my_snippet.html,只需执行以下操作:如上所述包含的视图将有权访问控制器返回的变量以及包含之前在父视图中定义的任何变量(以及模型中定义的全局变量,就像任何视图一样)。
You can use the
{{include}}
directive to include any view inside any other view. If you have /views/snippets/my_snippet.html, just do: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).