I am looking to create a dynamic page that can choose the appropriate CSS based on a routes.js file. My development is in node.js and pug, and I have explored different methods attempting to implement this functionality.
routes.js file
router.get("/", (req,res) => {
const indexCss = "rel='stylesheet' href='index.css' "
res.render("index"), {css:indexCss};
});
index.pug file
head
link(#{css})
title Index Page
Regrettably, my initial approach did not yield the desired results. I considered using link with req and body-parser but found it to be ineffective.
I believe implementing this feature would greatly benefit the organization and brevity of the code by allowing for a partial head inclusion with specified CSS from the routes.js file.
Despite my efforts, I find myself at an impasse. Does anyone have suggestions or ideas on how to achieve this?