如何在Mako中包含CSS文件?

时间:2011-11-08 23:47:30

标签: css pylons mako

我正在使用Mako模板进行项目。如何在Mako中添加CSS文件?

我尝试在<link type="stylesheet" type="text/css" href="<%include file='test.css' />" />标记中使用<head>,但它不起作用。

1 个答案:

答案 0 :(得分:2)

怎么样

${css_link('/css/filename.css', 'screen')}

来源:http://wiki.pylonshq.com/display/pylonscookbook/Including+CSS+And+Javascript+(etc.)+In+A+Flexible+Way+With+Mako

完整的示例代码:

<% self.seen_css = set() %>
<head>
    ${self.css()}
</head>

<%def name="css_link(path, media='')">
    % if path not in self.seen_css:
        <link rel="stylesheet" type="text/css" href="${path|h}" media="${media}"></link>
    % endif
    <% self.seen_scripts.add(path) %>
</%def>

<%def name="css()">
    ${css_link('/css/main.css', 'screen')}
    ${css_link('/css/navigation.css', 'screen')}
    ${css_link('/css/forms-buttons.css', 'screen')}
    ${css_link('/css/orders.css', 'screen')}
</%def>