如何在express.js中引用布局图像,以便可以从嵌套目录中找到它们? [英] How to reference layout images in express.js so that they can be found from nested directories?

查看:85
本文介绍了如何在express.js中引用布局图像,以便可以从嵌套目录中找到它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个express.js应用程序,当前正在使用ejs(在较新的项目中使用jade),并且我试图以一种干净且适当的方式解决问题。

I've got an express.js app currently using ejs (using jade for newer projects) and I'm trying to solve a problem in a clean and appropriate manner.

我有一个layout.ejs文件,其中包含页眉和页脚。到目前为止,我的大多数网站都深入了一层 http://innovationbound.com/about 或/ services或/艾米,等等。...

I've got a layout.ejs file with my header and footer in it. Most of my site so far has been one layer deep http://innovationbound.com/about or /services or /amy and so on....

我开始在 http://innovationbound.com/courses/course-name ,我遇到的问题是这些课程页面无法以相同的方式引用图像。例如,< img src = images / linknedin.png alt = LinkedIn Icon>

I'm beginning to created online courses at http://innovationbound.com/courses/course-name and the issue I'm having is that these course pages can't reference the images the same way. <img src="images/linknedin.png" alt="LinkedIn Icon"> for instance.

从课程名称页面尝试< img src = courses / images / LinkedIn.png alt = LinkedIn Icon> ; 显然无法在此处获取图像。

From the course-name page it tries <img src="courses/images/LinkedIn.png" alt="LinkedIn Icon"> and obviously can't grab the image there.

快递中有设置吗,还是我明显缺少的东西?我希望我不必使用绝对URL,这只会使在本地计算机上进行开发变得疯狂。

Is there a setting in express, or something obvious I'm missing? I hope I don't have to use absolute urls, that just makes developing on the local machine insane.

推荐答案

只使用站点根目录相对路径。例如,< img src = / images / linknedin.png alt = LinkedIn Icon> 。注意 / 有所不同。

Just use site root–relative paths. For example <img src="/images/linknedin.png" alt="LinkedIn Icon">. Note the / makes the difference.


链接路径有三种类型:

There are three types of link paths:

文档相对路径(例如dreamweaver / contents.html)。

Document-relative paths (such as dreamweaver/contents.html).

站点根目录相对路径(例如/support/dreamweaver/contents.html)。

Site root–relative paths (such as /support/dreamweaver/contents.html).

来自 Adob​​e

这篇关于如何在express.js中引用布局图像,以便可以从嵌套目录中找到它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆