views:

15

answers:

1

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?

A: 

I figured it out:

<!--#if expr='"$DOCUMENT_URI" = "/contact.html"' -->
    This is the contact page.
<!--#endif -->
mikez302