Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include

Status
Not open for further replies.

Sortarius

Programmer
Feb 1, 2005
4
US
I know the standard code for including a file:
<!--#include file="PageTitle.asp" -->

What I want to know is how I can write this as an If statement. Example:
If (Variable = Result) Then
<!--#include file="PageTitle.asp" -->
End If

Obviously this code doesnt work. What would be a workable version?
 
I don't know about current versions, but I think it was IIS 3 that would process all the includes before any of the script so that there was not really any way to do a conditional include.
 
Hi,
AFAIK, it still behaves that way..The include pages are loaded before any code is interpreted.

[profile]
 
Include the following function at the top of your page:


<%

'Pass the name of the file to the function.
Function getFileContents(strIncludeFile)
Dim objFSO
Dim objText
Dim strPage


'Instantiate the FileSystemObject Object.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")


'Open the file and pass it to a TextStream Object (objText). The
'"MapPath" function of the Server Object is used to get the
'physical path for the file.
Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))


'Read and return the contents of the file as a string.
getFileContents = objText.ReadAll

objText.Close
Set objText = Nothing
Set objFSO = Nothing
End Function
%>

Then where you would place your include file do the following:


If (Variable = Result) Then
response.write getFileContents("PageTitle.asp")
End If

This example can be found at:

Thanks,
Patrick Green
 
Sortarious,

Not sure if this is on the right track, but what the hey. By reading I gather you are trying to change the title of your page whenever the variable changed. Your code won't work because you have the include file within asp tags. It needs to be in the html.
Code:
<html>
 <head>
  <title>

<%

 ' used a constant...but you can make variable dynamic with a function
  var = 1
  
  If(var=1) Then
 ' Display the title page
%>

<!--#include file="PageTitle.asp" -->

<%
  Else
 ' don't display
  End If
%>
  
  </title>
</head>
<body>

<!-- Code -->

</body>
</html>
Hope this what you need...if not sorry...just trying to help

BSL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top