HPWD
HPWD

Reputation: 2240

ASP if x = y then include file a

First, ASP is not my thing, coldfusion is. I'm helping a not profit animal rescue group update a couple of seemingly simple items on their web site but I'm not proficient in ASP so it is proving to be harder than I expected. The person who setup the site for them put the slider on every single page. What they'd like to have done is to only have the page on the index.asp.

I came up with the following code logic but it isn't working. I've researched it and know the WHY it isn't working but I cant figure out the HOW to make it work.
UPDATED:

<% if(Request.ServerVariables("SCRIPT_NAME") = "index.asp") { %>
<!--#include file ="_slider.asp"-->
<% } %>

Any constructive guidance or links or fiddle would be much appreciated. I don't plan on helping much with the site, just until the primary developer returns from active duty.

UPDATED: I updated my code to include the slider as shown below but I'm still getting the non-descriptive page error.

<% 
Dim ThisPage
ThisPage = getFileName(Request.ServerVariables("SCRIPT_NAME"))
if ThisPage = "index.asp" Then %>
    <!--#include file="/includes/_mainPage_slider.asp"-->   
<% End If %>

Upvotes: 1

Views: 1753

Answers (2)

WilliamK
WilliamK

Reputation: 781

What you have tried to do is right but the syntax is wrong for Classic ASP. Try...

<% if Request.ServerVariables("SCRIPT_NAME") = "index.asp" then %>
<!--#include file ="_slider.asp"-->
<% end if %>

Upvotes: 0

Tom Collins
Tom Collins

Reputation: 4069

You have 2 problems.
First,
The Request.ServerVariables("SCRIPT_NAME") returns the full path & filename. If you only want to get the filename, you can use this function:

Function getFileName()
  Dim lsPath, arPath

  ' Obtain the virtual file path
  lsPath = Request.ServerVariables("SCRIPT_NAME")

  ' Split the path along the /s. This creates an
  ' one-dimensional array
  arPath = Split(lsPath, "/")

  ' The last item in the array contains the file name
  GetFileName =arPath(UBound(arPath,1))
End Function

Second,
You're using PHP, but you said you were using asp-classic. Not sure if you knew that. The above example is in VBScript (the main Classic ASP language). If you are using PHP, then you should be able to figure out how to translate it.

If you're trying to ASP, then using the above function, your code should look like this:

<% if(getFileName(Request.ServerVariables("SCRIPT_NAME")) = "index.aspx") Then %>
<!--#include file ="_slider.aspx"-->
<% End If %>

Reference

Upvotes: 2

Related Questions