简体   繁体   中英

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 (eg localhost/myapp/controllerA/controllerA.html)?

ejs look like:

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

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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM