PDA

View Full Version : conditional includes


Spudhead
04-30-2003, 05:16 PM
Am I going mad? I was under the impression that you couldn't do them; the INCLUDE directive gets processed at the same time as the ASP IF statement, so the file will be included regardless.

So how is this working:

<%
if infoFile = "swisscitycombinations.htm" then
%>
<!-- #include file="travel_info_tables/swiss.htm"-->
<br>
<!-- #include file="travel_info_tables/swisscitycombinations.htm"-->
<%
end if
%>


And it IS working - there's a whole bunch of statements like the one above in the file I've just found, and the wrong includes don't get included (if that makes sense :))

What's going on?

Roy Sinclair
04-30-2003, 06:26 PM
The includes are processed first, then the code is run. It's done that way so that code in the includes can be processed.

oracleguy
04-30-2003, 06:49 PM
The code from both files is being loaded, its just that it only runs the code from whatever makes the if statement true.

What you can't do is something like:
If strSomething=1 Then
strSSI="myfile.asp"
Else
strSSI="myfile2.asp"
End If

<!-- #Include File=strSSI -->

Roy Sinclair
04-30-2003, 09:46 PM
Originally posted by oracleguy
The code from both files is being loaded, its just that it only runs the code from whatever makes the if statement true.

What you can't do is something like:
If strSomething=1 Then
strSSI="myfile.asp"
Else
strSSI="myfile2.asp"
End If

<!-- #Include File=strSSI -->

But with IIS 5 you can do this:



If strSomething=1 Then
strSSI="myfile.asp"
Else
strSSI="myfile2.asp"
End If

Server.Execute strSSI

Spudhead
05-01-2003, 09:52 AM
Aha. A small lightbulb has just pinged on. Cheers guys.

oracleguy
05-01-2003, 04:37 PM
Did not know that Roy... thats a good thing to know. Thanks.