Dynamic Includes

07-11-2002, 08:14 AM
Okay, not sure how to accomplish this. I am setting up a template for a website which includes a header, a left hand side menu, a right hand side fact sheet, content, and a footer. The header and footer will be the same for each page, but the left and right include files will depend on which section and which page respectivly (both will be used on multiple pages). I want this template to be as self sufficient as possible so my idea was to set 2 variables at the top of the page - sSection (which dictates which left hand menu to include) and iRightCol (to tell which fact page to show for this page). Here's how I intended to do it:

<%Dim sSection, iRightCol
sSection = "About"
iRightCol = 1

<!-- code............ -->

<td><!-- #INCLUDE FILE = "includes/left<%=sSection%>.asp" --></td>
<td><!-- #INCLUDE FILE = "includes/right<%=iRightCol%>.asp" --></td>

However, this isn't working (can't dynamically build include statement). So how can I get around it where the person using the template doesn't have to search around in the code to change things? I would love to just train someone to change the first 2 lines when adding a page to the site. Any ideas?


07-11-2002, 10:48 AM
Well, you could use createobject with the filesystemobject, open
the correct include files and output them into the html page you
are creating in the asp script.

07-11-2002, 01:12 PM
To the best of my knowledge there is no way to make include file names dynamic in a general practice way. Thinker seems to have a good idea though.

I have tried to do this in the past and I believe I ended up using a select case, but this only works when you have a relatively small number of possible files.

select case Parameter

case 1
%> <!-- #include file="1.asp"<%
case 2
%> <!-- #include file="2.asp"<%
case else
%> <!-- #include file="3.asp"<%
end select

07-11-2002, 04:18 PM
Jaws is correct -- you can use #include files dynamically by use of conditional statements (If/Select Case).

To test it out, you can always throw some test code in and see if it fires. For example:'one.inc contents
Response.write "ONE.INC JUST FIRED!"

'two.inc contents
Response.write "TWO.INC JUST FIRED!"

If 99 < 100 Then
%><!-- #include file=one.inc --><%
%><!-- #include file=two.inc --><%
End If
%>Here, one.inc would be included but two.inc would not be. So, you would only see "ONE.INC JUST FIRED!" on the screen.

07-12-2002, 06:35 AM
Thanks guys. I ended up using a case statement. I had been just was trying to avoid that route since there are 20+ possible includes and I was attempting to make the code look clean and concise. I still might try the fileSystemObj method - that was one I hadn't thought of! Again, thanks for all of your guys' help!!!


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum