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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically including files 1

Status
Not open for further replies.

jasek78

Programmer
Nov 5, 2001
298
US
I am trying to set up a website with a basic template, which is created already, to include different text depending on which page is being created.

Here is my code. It gets the filename of the text to be included and inserts it into an include statement.

For now I am just testing it with no variables, so it tries to insert the "home.inc" text into the area.

Code:
If Request.QueryString("txtinc").Count > 0 then
 includeTXT= &quot;<!--#include file=&quot;&quot;inc/&quot; & txtinc & &quot;&quot;&quot;-->&quot;
Else
 includeTXT= &quot;<!-- #include file=&quot;&quot;inc/home.inc&quot;&quot;-->&quot;
End If

... And I put this line where I want the text to be included.
Code:
<% Response.write includeTXT %>

when I view source, the above line shows as
Code:
<!-- #include file=&quot;inc/home.inc&quot;-->

and does not work. The area that the text should be in is blank. Does anyone know why this is, and how I can accomplish this task?
 
It doesn't work this way - I ran into the same problem too.


Here's what you should do:

<%
If Request.QueryString(&quot;txtinc&quot;).Count > 0 then
%>
<!--#include file=&quot;inc/filename.inc&quot;-->
<%
Else
%>
<!-- #include file=&quot;inc/home.inc&quot;-->
<%
End If
%>

But that kinda defeats the whole purpose...

So you can do this

If Request.QueryString(&quot;txtinc&quot;).Count > 0 then
Server.Execute (&quot;inc/&quot; & txtinc)
Else
Server.Execute (&quot;inc/home.inc&quot;)
End If

I think that should work, I used it in similar situations.
If the include file is an html, it acts like an include statement.

Good luck
<Dmitriy>
dbrom@crosswinds.net
 
I'm pretty sure I read somewhere that the include files are included BEFORE any scripts are run. If that is the case, the first suggestion you gave me won't work. I tried the second, and it works if I don't call a txtinc variable.

It returns this error when it gets to the Server.Execute line.

Code:
Server.Execute Error 

/innovativa/web/asp/default.asp, line 157 

The call to Server.Execute failed while loading the page


 
I just looked at it in my code and it looks like I do it this way:

strFilename = &quot;inc/&quot; & txtinc
If Request.QueryString(&quot;txtinc&quot;).Count > 0 then
Server.Execute (strFilename)

It sure works for me (although I do it in JScript)

Also, make sure the path is correct - Response.Write(strFilename), and see if it shows the correct path to an existing file.

The first suggestion DOES work - I implemented it on on of my pages:


switch (clType)
{
case &quot;Soap Opera&quot;:%>
<!--#include file=&quot;imageIncludes/lasoap.inc&quot;-->
<%break;

case &quot;Cold Reading&quot;:%>
<!--#include file=&quot;imageIncludes/lacoldread.inc&quot;-->
<!--#include virtual=&quot;/include/rightad.inc&quot;-->
<%break;

case &quot;Sitcom&quot;:%>
<!--#include file=&quot;imageIncludes/lasitcom.inc&quot;-->
<!--#include virtual=&quot;/include/rightad.inc&quot;-->
<%break;

case &quot;Commercial&quot;:%>
<!--#include file=&quot;imageIncludes/lageneric.inc&quot;-->
<!--#include virtual=&quot;/include/rightad.inc&quot;-->
<%break;

default:%>
<!--#include file=&quot;imageIncludes/lageneric.inc&quot;-->
<!--#include virtual=&quot;/include/rightad.inc&quot;-->
<%break;

}

<Dmitriy>
dbrom@crosswinds.net
 
ah! Thank you for showing me the error of my code =^)

I did not mean to imply that it didn't work. I apologize for that. Thanks again. This saved me *tons* of work (at the least, I would've had to next like 20 if-thens or Select statements...

jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top