Konstantin Petrukhnov
Konstantin Petrukhnov

Reputation: 770

how specify relative image path in ejs (javascriptmvc)

I'm trying do simple application with javascriptmvc.

There is several controllers and next folder structure:

/controllerA
  /views
    view1.ejs
    /images
      img1.png
/controllerB
  /views
    view2.ejs
    /images
      img2.png

How do i refer to image in ejs files, so it work correctly in whole project, and in each controller separately (e.g. localhost/myapp/controllerA/controllerA.html)?

ejs look like:

<div class="show-control">
  <img src="images/img1.png" alt="Show"/>
  <div class="count"></div>
</div>

Upvotes: 1

Views: 4311

Answers (1)

chovy
chovy

Reputation: 75686

You should put your images in ./project/public/images not in ./project/views/images

Then you can just use relative path with a forward slash /

  <img src="/images/img1.png" alt="Show"/>

Upvotes: 1

Related Questions