Before I begin, let me state that this idea came originally from a coleague, Nuno Baptista, with whom I'm proud to work with. Having said that and apologizing for any spelling errors, let's begin.
What's one of the worst things developers have to deal with? I'm guessing, besides clients , design. And the same is valid in reverse. To properly conciliate design and development is sometimes a major headache. So, how on earth do we solve this? Templates of course. PHP users are very familiar with them. How about ASP users? I really haven't found a easy an fast way to do it until I began at my current job.
Let's take it by steps.
1st - The design issue
Have your designer fun around all they want and then insert html comments were the information should go. For example:
'CODE START Function ReadTemplateFile (FilePath, FileToOpen)
Dim fs, f, line
line = ""
set fs=CreateObject("scripting.filesystemobject") If fs.FileExists(Request.ServerVariables(4) & FilePath & FileToOpen) Then set f=fs.OpenTextFile(Request.ServerVariables(4) & FilePath & "\" & FileToOpen) Do While not f.AtEndOfStream line= line & f.ReadLine() line= line & VbCrLf Loop f.Close else line= "The file " & Request.ServerVariables(4) & FilePath & FileToOpen & " was not found!" end if
ReadTemplateFile = line
Save this function into an include file, eg: functions.asp
3rd - The glue that makes it work
Create your asp file. Could be a search script with access to a database or anything else. Anything you want or need.
Finally, include the function file in you asp file and make it work:
'START CODE <!--#INCLUDE Virtual="/includes/functions.asp"--> <% Dim result result = ReadTemplateFile ("mypath\", "file1.html")
'DO WHATEVER YOU HAVE TO Dim myTitle Dim myStyle Dim myInfo
'REPLACE COMMENTS WITH DYNAMIC INFO result = replace (result, "<!--title-->", myTitle) result = replace (result, "<!--style-->",myStyle) result = replace (result, "<!--information-->", myInfo)
'SEND THEM TO THE BROWSER Response.Write(result) %>
And you're all done. Best of all, everytime design changes, you only have to see were the info has to be replaced and also replace the html file name and/or path if needed.