[Grok-dev] How do I use browser-specific stylesheets with grok?

Martijn Faassen faassen at startifact.com
Wed Jan 6 10:09:16 EST 2010


Hey,

Marcel Klapschus wrote:
> I want to use two different stylesheets for my templatepage (one for
> IE-Browser, the other for non-IE-Browser). The two stylesheets are placed in
> my static folder, but since tags like "<!--[if IE]>" just ignore my
> "tal:attributes href", I have no idea how to add the path to my css files
> here.
> 
> This is what I try in template:
> 
>     <!--[if IE]>
>     <link rel="stylesheet" type="text/css"
>           tal:attributes="href static/menu_ie.css"/>
>     <![endif]-->
> 
>     <!--[if !IE]>
>     <link rel="stylesheet" type="text/css"
>           tal:attributes="href static/menu.css"/>
>     <![endif]-->
> 
> The lines "tal:attributes="href static/menu....." are ignored :-(

Aah, I imagine that's because ZPT is not processing inside of comments?

You could hack your away around it: create a view with a method 
"render_css_includes" or something that just returns the right bits you 
need and then use <tal:block replace="structure view/render_css_includes">

You can produce static URLs from Python by... hmm, I *think* you should 
be able to something like the following:

def render_css_includes(self):
     resource_url = self.static['menu.css']()
     return "<link href="%s"></link>" % resource_url

Regards,

Martijn




More information about the Grok-dev mailing list