'Include a CSS file for a partial in EJS

how do i include a separate css file for a ejs partial? So for example i have sidebar.ejs that will be embedded into the index.ejs, how would i include sidebar.css into the sidebar.ejs file since it does not have a head section to add the link.

ejs


Solution 1:[1]

You can add a head to the top of your index.ejs and import whichever partial you want. This screenshot is from a project I'm currently working on, but this is my index.ejs template and you can see I've included a <head>...</head>. This section will not render with the rest of the HTML. In your case, you could import sidebar.css into whichever <head>...</head> you wanted it to be linked to.

ejs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jacver