4

I'm using Mako template for a project. How can I add a CSS file in Mako?

I try to use <link type="stylesheet" type="text/css" href="<%include file='test.css' />" /> in the <head> tag, but it doesn't work.

KatieK
  • 13,586
  • 17
  • 76
  • 90
  • 1
    Can you be more specific about "doesn't work"? Is there an error (if so, what)? What source code is generated? – KatieK Nov 09 '11 at 01:06

1 Answers1

2

How about

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

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

Complete example code:

<% 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>
Yisela
  • 6,909
  • 5
  • 28
  • 51