henry.oswald
henry.oswald

Reputation: 5434

Jade - calling page specific css pages

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

Upvotes: 0

Views: 1095

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146084

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.

Upvotes: 3

Related Questions