|
 |
asp_web_howto thread: Dynamic Include Statement
Message #1 by "Jerry Mounce" <jerry_mounce@m...> on Wed, 28 Nov 2001 00:11:05
|
|
I would like to pass a variable to an Include statement. For example:
currPath = Request.ServerVariables("PATH_INFO")
<!--#Include virtual="<%=currPath%>/myFiles.asp"-->
This statement does not work nor several other iterations I have tried.
My questions are:
If it is possible to pass a variable to the Include statement what is the
correct method / syntax?
If not is there a method to build an Include statement programatically?
Thanks,
Jerry Mounce
Message #2 by "Ken Schaefer" <ken@a...> on Wed, 28 Nov 2001 11:30:17 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Jerry Mounce" <jerry_mounce@m...>
Subject: [asp_web_howto] Dynamic Include Statement
: I would like to pass a variable to an Include statement. For example:
:
: currPath = Request.ServerVariables("PATH_INFO")
: <!--#Include virtual="<%=currPath%>/myFiles.asp"-->
:
: This statement does not work nor several other iterations I have tried.
:
: My questions are:
:
: If it is possible to pass a variable to the Include statement what is the
: correct method / syntax?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
No, it is not possible. Include directives are processed *before* the ASP
is. When you think about it, this becomes logical. All the includes are
included "into" the main page. Then all the combined ASP code is intepreted.
How else could it work?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If not is there a method to build an Include statement programatically?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I suggest you encapsulate the include functionality into routines (functions
and subs). Include all the relevant routines, and then programatically call
the routine you require.
Cheers
Ken
Message #3 by "Daniel O'Dorisio" <daniel@o...> on Tue, 27 Nov 2001 19:27:42 -0500
|
|
--------------------------
> I would like to pass a variable to an Include statement. For
> example:
--------------------------
sorry, that dosnt work.. as much as we wish it did it dosnt.. server side
directives are processed before the asp script.. meaning that you can not
use asp vars or criteria in the ssi directive.. here are your alternatives..
1. in iis 5 use server.execute, this can be done, i use it on one of my
sites to dynmaically process a page layout file, for example, i set my pages
up with including several files. begin.asp, end.asp, head.asp and site.asp..
begin and end hold the layout info, like the global table.. so sometimes on
a page i want this and sometimes i dont.. (printable or whatever) i use the
server.execute method to dynamically execute that script inline.. something
like:
<%
if blnVal = true then
server.execute "begin.asp"
end if
%>
2. you can put all your includes together, and seperate them with subs and
functions. then include the whole page, and call your function..
that is about all i can think of.. one of the wiser members of the list may
have better ideas..
hth
daniel
--
-----------------------------
Daniel O'Dorisio
daniel@o...
www.odorisio-networks.com
-----------------------------
Message #4 by "Ken Schaefer" <ken@a...> on Wed, 28 Nov 2001 11:51:42 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If not is there a method to build an Include statement programatically?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Addendum,
If you have IIS v5 you can look at using Server.Execute to dynamically
transfer execution to another page - but I prefer using routines. Modular
code is preferable to doing transfers to inline code.
<%
If blnFoo then
Server.Execute("foo.asp")
Else
Server.Execute("bar.asp")
End If
%>
Cheers
Ken
Message #5 by "nick wardle" <nwardle@b...> on Fri, 30 Nov 2001 19:07:26
|
|
> If you have IIS v5 you can look at using Server.Execute to dynamically
> transfer execution to another page - but I prefer using routines. Modular
> code is preferable to doing transfers to inline code.
>
> <%
> If blnFoo then
> Server.Execute("foo.asp")
> Else
> Server.Execute("bar.asp")
> End If
> %>
>
> Cheers
> Ken
>
Ken, I agree, modular code is absolutely better.. however, I am a bit new
to VB scripting and I would appreciate a little further explanation...? : ]
I am attempting something v similar to the above: master.asp contains four
#includes - header.asp, menu.asp, body.asp, footer.asp. not too complex.
except that body.asp also contains #includes, and these have variable
filenames,
these filenames are generated by sorting a database, using a "pageID"
collected from the QueryString, into a Recordset...
and returning the relavent filename(s) (oh yeah, also using a Repeat loop
if there is more than one filename in that pageID section of the dbase...)
from the database.
By just using :
aStr = "string"
aStr = aStr & "morestring"
etc..
Response.Write (aStr)
...I have built the <!-- #include file="(Recordset.field etc...
statements, but of course, the #includes need to be resolved BEFORE the
VB, so all I end up with is master.asp that has some HTML and some nicely
printed out <!-- # include file="(Recordset.field etc.. --> statements
half way down it!!
so.... (sorry this so long)
I was hoping you might be able to SPELL OUT FOR ME (coz I am thick at
this.. ; ] ) an example of the routines / modular code you were talking
about. or maybe just point me to an example I could reverse engineer for
myself?
oh yeah.. how do I know if I have IIS 5... I am running Personal Web
Server on NT4 (srv pack 6)? (that might be a stupid question.. I just
don't know.. <grin>)
thanks in advance, any help you could offer would be greatly
appreciated! : ]
nick
|
|
 |