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.
精彩评论