我有一个带有动态数量的小部件的网站,金字塔视图(views.py)调用页面,并发送数据:
查看.py:
@view_config(route_name='home', renderer='templates/home.pt')
def home_view(request):
widgets = #do sql stuff#
return widgets
布局.t:
<html>
<head>
<title>Title</title>
</head>
<body>
<div class="container">
<div tal:omit-tag="" metal:define-slot="content"/>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<more tal:omit-tag metal:define-slot="js-more"></more>
</body>
</html>
主页.pt:
<div metal:fill-slot="js-more">
<script src="pagespecific.js"></script>
</div>
<div metal:use-macro="load: layout.pt">
<div metal:fill-slot="content">
Page Content!!!!
</div>
<div class="widgets-stuff">
<div class="modulecontent" tal:repeat="_widgets widgets">
<div tal:omit-tag="" metal:use-macro="load: widgets/${_widgets.template}.pt" />
</div>
</div>
</div>
小部件示例.pt:
<div class="morewidgetstuff">
A widget!
</div>
我希望能够在小部件模板上添加一个新的 js,如下所示:
小部件示例.pt:
<div metal:add-to-slot="js-more">
<script src="widgetspecific.js"></script>
</div>
<div class="morewidgetstuff">
A widget!
</div>
ps:我知道这没有多大意义,这只是一个例子