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

*%/£** include files!!!!!

Status
Not open for further replies.

paulcarey

Programmer
Jun 15, 2001
45
GB
Dear Genii!

I have an asp page seperated into areas via a table. Between one of the <td></td> tags I need to insert an include page. Here's the crunch.....it needs to be picked via a variable, this is something 'include' will not support.
I have tried 'including a page that uses redirect. Although this accepts the variable it opens the new page selected in a new window and not between the tags as specified in page one.
Maybe a function? I'm pretty clueless here!

Paul

 
In this type of case, I usually just write one big include file with response.write's of what I want in the different include files...

like say you have a possible four include files, then your new include file would have four functions, each with response.write's of what would have been in the individual include files, and then you can use a select case statement to decide which function to call.

:)
Paul Prewett
penny.gif
penny.gif
 
Mr link9

I am very new to this and therfore dont really understand!!

Can you elaborate?

Paul
 
Another possbility if you're only talking a few includes (and if I'm understanding it correctly) could be ..
<%select case varA
case &quot;index.asp&quot;%>
<!--#include file=a.asp -->
case &quot;links.asp&quot;%>
<!--#include file=b.asp -->
case else%>
<!--#include file=c.asp -->
<%end select%>

This is not necessarily the best solution (as I believe it grabs and checks the syntax of ALL includes even if they're not used), but it is an option. <insert witticism here>
codestorm
 
Here's a simplified example. Say you have two include files.

(1)
Here's some text from include file 1

(2)
Here's some text from include file 2

So that you would like to do something like this:

<%
if someCondition then%>
<!-- #include file=&quot;include1.inc&quot; -->
<%
else%>
<!-- #include file=&quot;include2.inc&quot; -->
<%
end if%>

So that you would just get the text of the include file output to the screen based on the value of someCondition, right?

Well, that doesn't exactly work, as you have figured out.

So my workaround is to make one include file, and it would look like this:

<%
function include1()
response.write(&quot;Here's some text from include file 1&quot;)
end function

function include2()
response.write(&quot;Here's some text from include file 2&quot;)
end function
%>

I would name it include.inc (or whatever works for you) and then include it on your page like this:

<!-- #include file=&quot;include.inc&quot; -->

Then, my conditional would just look like this:

<%
if someCondition then
include1
else
include2
end if
%>

So you get your desired effect of &quot;different&quot; include files, but all in one include file, simply calling the appropriate function where needed.

hope that helps. :)
Paul Prewett
penny.gif
penny.gif
 
Interesting, link9.
I have used the example I put above successfully before.
Maybe it depends on the Web Server's handling of includes. <insert witticism here>
codestorm
 
Interesting, indeed. I have never been able to get that type of method to work. Maybe I'll dig a little deeper on it.

Thanks for the info.

:)
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top