服务器端包含有什么方法可以获取包含该文件的文件名或 URL?
服务器端包含有什么方法可以确定它被包含在哪个文件中?我想做这样的事情:
<ul id="menu">
<!--#if expr="$URL = index.html" -->
<li><span>Home</span></li>
<!--#else -->
<li><a href="index.html">Home</a></li>
<!--#endif -->
<!--#if expr="$URL = about.html" -->
<li><span>About us</span></li>
<!--#else -->
<li><a href="about.html">About us</a></li>
<!--#endif -->
<!--#if expr="$URL = contact.html" -->
<li><span>Contact us</span></li>
<!--#else -->
<li><a href="contact.html">Contact us</a></li>
<!--#endif -->
</ul>
我只需要知道是否可以使用服务器端包含,如果可以,语法是什么。
我对服务器端包含做了一些研究,并尝试了这样的事情:
<!--#if expr="DOCUMENT_URI = /contact.html" -->
this is the contact page
<!--#endif -->
我在输出中看到了这一点:
[处理此指令时发生错误]这是联系页面
就像它正在理解命令一样,但由于某种原因某些东西导致了错误。
我尝试使用 SCRIPT_FILENAME、REQUEST_URI、SCRIPT_NAME 和 DOCUMENT_NAME 代替 DOCUMENT_URI 进行类似的操作,无论有或没有所需的路径信息,在每种情况下,我都能使其工作,但我收到了该错误消息。有谁知道什么会导致这种情况?
Is there any way for a server-side include to determine what file it is being included in? I would like to do something like this:
<ul id="menu">
<!--#if expr="$URL = index.html" -->
<li><span>Home</span></li>
<!--#else -->
<li><a href="index.html">Home</a></li>
<!--#endif -->
<!--#if expr="$URL = about.html" -->
<li><span>About us</span></li>
<!--#else -->
<li><a href="about.html">About us</a></li>
<!--#endif -->
<!--#if expr="$URL = contact.html" -->
<li><span>Contact us</span></li>
<!--#else -->
<li><a href="contact.html">Contact us</a></li>
<!--#endif -->
</ul>
I just need to know if it is possible using server-side includes, and if so, what the syntax would be.
I did some research on server-side includes and tried something like this:
<!--#if expr="DOCUMENT_URI = /contact.html" -->
this is the contact page
<!--#endif -->
And I see this in the output:
[an error occurred while processing this directive] this is the contact page
like it is understanding the command but something is causing an error for some reason.
I tried similar things with SCRIPT_FILENAME, REQUEST_URI, SCRIPT_NAME, and DOCUMENT_NAME in place of DOCUMENT_URI, with or without the required path information, and in each case, I was able to make it work but I got that error message. Does anyone have any idea what would cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了:
I figured it out: