Just don’t. Ever.
Good grief, that’s been a frightening few days. And all because I rushed something on Tuesday night that wasn’t that urgent after all. Now, who’s going to place bets that this (finally) teaches me a lesson. 200-1, I reckon.
But it does give me a good excuse to post my first proper code example. This one is classic ASP (VBScript), and is very useful when you need to hard-write a lot of files with only minor changes such as the title, keywords, description and a bit of page content between them. You can always see it in action as well, if you want. Oh, and one more thing, this (and any code peovided on this blog) is given without any guarantees or warranty whatsoever.
' all you need to do to that is create your html template and replace some
' of the elements in it with the codified equivalents. here's a list:
' page title = %%pagetitle%%
' meta keywords = %%pagekeywords%%
' meta description = %%pagedescription%%
' page content = %%pagecontent%%
' level (string of ../'s to the root, for image paths etc) = %%lev%%
' grab the template file
templatepath = "template.htm"
Set f=fs.OpenTextFile(Server.MapPath(templatepath), 1)
bodytext = f.readall
' this is the function that is called to create the final HTML code
getbody = bodytext
getbody = "" & vbcrlf & getbody
getbody = replace(getbody,"%%pagetitle%%",pagetitle)
getbody = replace(getbody,"%%pagekeywords%%",pagekeywords)
getbody = replace(getbody,"%%pagedescription%%",pagedescription)
getbody = replace(getbody,"%%lev%%",lev)
getbody = replace(getbody,"%%pagecontent%%",pagecontent)
' start your loop (from a database, for example)
' for each item create the HTML and save the file like this:
tfile.Write getBody(bodytext,"Page title","keywords","description","../../../","This is the page content")
' go to the next item