开发者

Jade - calling page specific css pages

开发者 https://www.devze.com 2023-04-12 15:01 出处:网络
I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this开发者_如何学Python elegantly?This should do it

I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this开发者_如何学Python elegantly?


This should do it

link(rel="stylesheet", href="#{req.path + '.css'}", type="text/css")

Where you pass either req (the request object) as a local variable when rendering the jade template (or even just pass in req.path as path). This could just be handled in your layout.jade and it will work for each of your route paths.

If you want to get fancy, you could establish a consistent pattern where a page's route maps 1 to 1 to a filesystem path for a .css file in your public directory. In that case you could easily but the stylesheet link tag inside a conditional and only link to the .css file if you find a matching one on disk.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号