【发布时间】:2014-10-16 11:21:15
【问题描述】:
我正在尝试 this method 将静态包含添加到我的命名空间,但我面临的问题是,来自嵌套命名空间的静态包含不包含在基本模板中。为了使问题更具体,下面我发布一些示例代码:
base.mako
<!DOCTYPE html>
<head>
% for ns in context.namespaces.values():
% if hasattr(ns, 'includes'):
${ns.includes()}
% endif
% endfor
</head>
<body>
${next.body()}
</body>
</html>
child.mako
<%inherit file="base.mako"/>
<%namespace name="rb" file="buttons.mako"/>
${rb.render_buttons}
buttons.mako
<%namespace name="lib" file="lib.mako"/>
<%def name="includes()">
<script type="text/javascript" src="${request.static_url('project:static/lib.js')}"></script>
</%def>
<%def name="render_buttons()>
<button onclick="some_function_from_lib_js()">Click me!</button>
${lib.render_text()}
</%def>
lib.mako
<%def name="includes()">
<script type="text/javascript" src="${request.static_url('project:static/other.js')}"></script>
</%def>
<%def name="render_text()">
<button onclick="some_function_from_other_js()">No! Click me!</button>
</%def>
这只是一个例子,但我希望它足以描述我的问题。
【问题讨论】: