Forum Moderators: phranque

Message Too Old, No Replies

SSI pages with conditionals not properly parsed

could not find appropriate SSI forum

         

KenW

5:24 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



The problem I have is that the output from an SSI include with conditional statements in it does not display properly.

I am trying to use SSI files called from ASP pages to include a menu whose content is based on what page calls the include. Basically, I don't want to have a link in my menu back to the page I am already on. This is for a division's website in a very large work environment. I do not have control of the webserver the pages are hosted on. I have contacted IT and confirmed that SSI includes are active from ASP files but they would not tell me what OS the hosting machines are running nor whether this is run through Apache or IIS.

I call an SSI file with the following relavent code from an ASP page:


<html>
<!--#set var="thisis" value="administration" -->
...
<!--#include file=menu.ssi-->
...
</html>

Here is a snippet of the code from my 'menu.ssi' page:


<div style="float: left;" >
<table style="width: 175px; text-align: left;">

<!--#if expr="$thisis = /default/" -->

<tr>
<td>
<img class="menuTable" src="../assets/images/Home.gif" id="" alt="Home" />
</td>
</tr>

<!--#else -->

<tr>
<td style="padding-left: 5px;" >
<a class="menuHover" href="../default.htm">Home</a>
</td>
</tr>

<!--#endif -->

<!--#if expr="$thisis = /administration/" -->

<tr>
<td>
<a href="../html/administration.html"><img class="menuTable"
src="../assets/images/Administration.gif" id="Administration" alt="Administration" /></a>
</td>
</tr>

<!--#else -->

Test

<!--#endif -->

...

<p style="text-align: center">
...
Other Menu Content Here
...
</p>

</table>
</div>

The output is in the following order, items in ()s are actual images displayed as they are formatted:


Test
Other Menu Content Here
(the Home.gif image)
Home
(the Administration.gif image)

Other SSI includes which do not have conditionals in them work normaly when called from this ASP file. I searched the forums here and found some information about a similar problem for php files calling SSI where global variables were turned off. The post suggested this fix which did not work:


<!--#if expr="$_ENV['thisis'] = /default/" -->

instead of


<!--#if expr="$thisis = /default/" -->

I am fairly new to all this so any tips or tricks along with an answer to my prolem are more than welcome.

Span

9:00 pm on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!--#set var="thisis" value="administration" -->

Hi,
in your case, there should be an 'environmental variable' value.
You are using page names in your other conditions so maybe you should try this:

The include in your page:
<!--#include file="menu.ssi" -->

And the conditional stuff in your menu.ssi:
<!--#set var="thisis" value="$DOCUMENT_NAME" -->
<!--#if expr="$thisis = /default/" -->
Home code
<!--#elsif expr="$thisis = /administration/" -->
Administration code
<!--#elsif expr="$thisis = /resources/" -->
Links code
<!--#else -->
If nothing
<!--#endif -->

KenW

12:43 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



Thanks very much for the help Span, let me make sure I'm understanding your post correctly.

[quote]And the conditional stuff in your menu.ssi:
<!--#set var="thisis" value="$DOCUMENT_NAME" -->[\quote]

Should I not set the variable in my ASP page at all? Will $DOCUMENT_NAME set the variable to the name of the ASP page that calls menu.ssi? I'm new to this like I said and I had no idea it would work that way.

I was trying to keep menu.ssi small by using multiple if/else but they way you're suggesting of having the entire menu code for each condition should get around the issue I'm having. Thanks again for your help.

Span

9:46 am on Apr 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, $DOCUMENT_NAME will set the variable to the name of the page. If you want the directory name in there you could use $DOCUMENT_URI.

If you like it better there's no reason not to use multiple if/else.

Also, I see I made a mistake in my previous post. SSI needs elif instead of elsif.

KenW

7:19 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



After quite a bit of research it seems I can't do things the way I am trying because ISS conditionals don't work when called from ASP pages. Apparently the files are included before any of the code is checked and that is why the if statements aren't working. It seems I need to use some VBscript instead of the SSI conditionals and that should fix my problem. Thank you for trying to help me out in a losing cause Span.

KenW

5:16 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Well I finally figured it out. I wound up including an .asp file with some basic vbscript in it. The relevant snippet of code with conditionals looks like this:


<% if callingPage = "administration" then %>
<tr><td><a href="../html/administration.html"><img class="menuTable" src="../assets/images/Administration_HTextMenu.gif" id="Administration" alt="Administration" /></a></td></tr>
<% else %>
<tr><td style="padding-left: 5px;" ><a class="menuHover" href="../html/administration.html">Administration</a></td></tr>
<% end If %>

The original problem was that the text in my .ssi file was included into my .asp page but the conditionals were never parsed. By including an .asp page instead of .ssi, the conditionals in the vbscript are parsed correctly.