Jade - calling page specific css pages

元气小坏坏 提交于 2020-01-14 05:34:10

问题


I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this elegantly?


回答1:


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.



来源:https://stackoverflow.com/questions/7718342/jade-calling-page-specific-css-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!