Dynamic Includes

jenn5175
07-11-2002, 09: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><!--content--></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?

Jenn

Thinker
07-11-2002, 11: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.

Jaws
07-11-2002, 02: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.

ie
select case Parameter

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

Rezner
07-11-2002, 05: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 --><%
Else
%><!-- #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.

jenn5175
07-12-2002, 07: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!!!


Jenn

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum