Search code examples
pug

Use a local image in Pug 2.0.3


I have the following folder structure:

-project  
  -images  
    -logo.png  
  -views  
    -layout.pug

In the layout.pug file I am trying to reference the image found at project/images/logo.png and my efforts to use a relative path have failed.

img(src="project/images/logo.png" alt="Project Logo")
img(src="../images/logo.png" alt="Project Logo")
img(src="./images/logo.png" alt="Project Logo")
img(src="/images/logo.png" alt="Project Logo")

This is the first project where I am using pug, but I think I need to tell pug to require the image somehow, I just don't know how. How can I use a local image within a pug template? Is there any additional software required to do this?


Solution

  • I had forgotten to serve up the static content using express. by putting the images folder into my public folder and serving up the public folder in express this solved my problem. Within the app.js file I added

    express.use('public');