including header html page in main page

Results 1 to 3 of 3

Thread: including header html page in main page

  1. #1
    Join Date
    Dec 1969

    Default including header html page in main page

    I am trying to inclucde a header html page on another page. This is easy enough to do using &#060;!--#include file="sidebar.htm"--&#062; but I need to be able to read the name of the header from my databse first. It appears that you cannot do something like &#060;!--#include file="&#060;%=somefile.htm%&#062;"--&#062; because of server scripting limitations. Does anyone have a suggestion to how this can be achieved using asp?<BR><BR>Thanks in advance,<BR><BR>Rudi

  2. #2
    Join Date
    Dec 1969

    Default RE: including header html page in main page

    I think the work around is to use server.execute

  3. #3
    Join Date
    Dec 1969

    Default this is called

    dynamic include<BR><BR>you want to dynamically (programatically) select the file to include.<BR><BR>Although not entirely impossible, this is not handy with ASP (because includes are made BEFORE the script is interpreted)<BR><BR>So first you should consider that it is NOT doable. If you still want to find a turn around you can read the following. Good Luck<BR><BR>dynamic ASP includes:<BR>It is usually believed that dynamic includes DO NOT exist. Truly, as such, they don&#039;t but <BR>If you * really want* to include dynamically this is a turn around<BR>&#060;% &#039; === INCLUDE ASP ===<BR><BR>sub include(file)<BR> dim Fnm,inF,code,asp,pt1,pt2<BR> &#039; create FSO if necessary<BR> if not isobject(FSO) then _<BR> set FSO = Server.CreateObject("Scripting.FileSystemObject")< BR> &#039; retrieve file path<BR> Fnm = server.mapPath(fichier)<BR> &#039; if file exits<BR> if FSO.fileExists(Fnm) then<BR> set inF = FSO.openTextFile(Fnm,1,false)<BR> &#039; read all its content<BR> code = inF.readAll<BR> inF.close<BR> pt1 = 1 : pt2 = -1<BR> &#039; then , depending...<BR> while pt1&#062;0<BR> pt1 = INSTR(pt2+2,code,"&#060;"&"%")<BR> &#039; excecute what is between &#060; % and % &#062;<BR> if pt1&#062;0 then<BR> response.write MID(code,pt2+2,pt1-pt2-2)<BR> pt2 = INSTR(pt1+2,code,"%"&"&#062;")<BR> asp = MID(code,pt1+2,pt2-pt1-2)<BR> execute asp<BR> &#039; display the other stuff<BR> else<BR> response.write MID(code,pt2+2)<BR> end if<BR> wend<BR> &#039; otherwise message error<BR> else<BR> response.write "not found " & Fnm<BR> end if<BR>end sub<BR>%&#062;<BR><BR>Usage <BR><BR><BR><BR>you only need to invoque (without( as it ia s sub... ;o) <BR><BR>&#060;%include "mydirectory/page.asp"%&#062;<BR><BR> or by combining the file name<BR><BR>&#060;% dir="mydir" : lng="En"<BR>&#039; ...<BR>include dir & "/page_" & lng & ".asp"<BR>%&#062;<BR><BR>A good exemple is the dynamic inclusion of skins<BR><BR>&#060;%<BR>skin = request.cookies("skin")<BR>if skin = "" then skin = "maunakea"<BR>&#039; ...<BR>include dir & "/skins/" & skin & "/top.asp"<BR>&#039; ... general code <BR>include dir & "/skins/" & skin & "/bottom.asp"<BR>&#039; ...<BR>%&#062;<BR><BR>Important notes<BR><BR>The file to be included can have ant extension ... the ASP code will be recognized thanks to its tags &#060;% and %&#062; which are specific to ASP... <BR>The file can include both ASP and HTML mixed... <BR><BR>BUT:<BR>this usual shortcut ASP &#060;%=myvar%&#062; is not supported...<BR>You can only use &#060;%response.write myvar%&#062; <BR><BR>I hope this can help. I have not had a chance to test it myself. It comes from an French PHP-ASP site<BR>which now seems to have an english version <BR><BR>this is a comment by B. Wilkinson<BR>----------<BR>Bill Wilkinson - 4/7/2002 10:47:10 PM<BR>-----------<BR> It works--with some limitations--but it is very, very inefficient! <BR><BR>I would *highly* recommend that, if you want to use this technique, you do *NOT* have mixed ASP and HTML in the include file! Instead, have *ONLY* ASP code (and don&#039;t bother with the &#060;% and %&#062; tags. <BR><BR>The reason: The Execute statement in VBScript is very, very costly because to make it work the ASP engine has to essentially re-build an ASP page on the fly, suspending the operation of the current script and yet maintaining all the scoping information. Among other things, it means that the normal ASP caching mechanisms for often used ASP files can&#039;t be used. <BR><BR>This is an interesting concept, but I would keep it as a very, very, very last resort. If you only have three or four choices as to which file you might include, I think you&#039;d be better off with three or four separate ASP pages, instead. <BR><BR>You also need to be very careful of "scoping" rules and duplicate DIMensioning of variables. It would be *really* easy to make a mistake that would cause a compilation error in the Execute&#039;ed code that would be a nightmare to track down. <BR><BR>Having said all the above... If you must use it, yes, it&#039;s there. <BR>-------------<BR><BR>So the idea is to keep ASP and HTML as separate as can be to improve efficiency.<BR><BR>Let&#039;s know if it worked for you...<BR><BR>Enjoy ! <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts