首页 > 解决方案 > How to correctly reference .css file from handlebars while making /public/css and /public/img folders static?

问题描述

I am having trouble making my handlebars file access my .css file. My current folder structure looks like this:

root
  public
    css
      base.css (css file)
    img
      ping.png (image file)

I am currently making /public/img folder and /public/css folder static using this code:

['css', 'img'].forEach(folder => app.use(express.static(__dirname + '/../public/' + folder)));

And I am referencing my .css file from handlebars using this code:

<link rel="stylesheet" href="/base.css" type="text/css" media="screen" title="no title" charset="utf-8">

I have tried to use other answers that are on stackoverflow but I don't think the answers work the same way for my project.

Is there any other mistake that I am making here? Thank you.

标签: csshandlebars.js

解决方案


我解决了我的问题。由于我制作 /public/css 文件夹和 /public/img 文件夹的 .js 文件与 /public 文件夹位于同一目录中,因此我应该使用['css', 'img'].forEach(folder => app.use(express.static(__dirname + '/public/' + folder)));


推荐阅读