2016年7月29日 星期五

Includes Files Dynamically

下面說明,因為include 為SEVER SIDE SSI語法,所以前後的if、select判斷式都不會執行

http://www.learnasp.com/freebook/asp/inc.aspx
Include Files
The include option is the heart of making efficient ASP files and re-usable chunks. It basically 
has two forms and now we will present the forms and their differences:
<!--#include virtual="/whatever.asp"-->
would include any file on your site (in this example, whatever.asp is in the web server's root directory) 
but you must fully qualify the filename with a path.
<!--#include file="whatever.asp"-->
can include the whatever.asp file in  the directory of the script that contains the statement. 
It ASSUMES the current directory!
Example #1<!--#include virtual="/sally/filename.asp"--> 
could include a file from sally's directory, even if the page with this statement is (for example) 
in the /fred/finance folder.
Example #2:<!--#include file="/sally/filename.asp"-->
will fail from fred's directory.
Example #3:<!--#include file="../sally/filename.asp"-->
will succed from fred's directory but if the script that contains it is moved to a different level in the tree structure 
it will fail to locate the file. INCLUDE VIRTUAL is better if a script may be moved and is immune to relative path issues.
IMPORTANT: Include files are always processed and inserted before ASP scripts on the page are calculated. Thus a page with many IFs and SELECT CASEs that selectively include files in fact always include the file before the script begins executing.


請參考下面的動態載入方式
Includes Files Dynamically
The include files are gathered and processed BEFORE any ASP code. Soif your code looks like this:
<%SELECT CASE 
     CASE 1 %>
    <!--#include virtual="whatever1.asp"-->
     CASE 2 %>
    <!--#include virtual="whatever2.asp"-->     CASE 3 %>    <!--#include virtual="whatever3.asp"-->
<%END SELECT%>
Three includes are performed before any ASP code is executed.
YOU CANNOT DO:
<%
     whichfile="1"%>
  <!--#include virtual="whatever<%=whichfil%>.asp"-->
Though this is a reasonable idea.
<!--#include virtual="whatever.asp"-->
We however have coded a workaround that is FREE you may find useful. The workaround is:
   filename=/learn/test/includedynamic.asp

沒有留言:

張貼留言