<%
/*************************************** *********************************/
/* JScript template System
@ Author jxfsuda
@ Date 2010-9-27
@ See this template is applicable to servers that do not have the FSO permission and are not prepared to store the template to the database site for use.
The default template path is in the template directory at the same level as the file.
Use the HTTP request of the server to obtain the template content.
The following conditions must be met: the server can access the Internet and the server can access the content of the site.
The variable Writing Method $ {variable name}, $ {method name (method variable)} in the template conforms to the jstl writing habits.
The variable name or method name must already exist and be accessible.
Example: $ {user. Name }$ {getarticle (0, 1, false )}
There is nothing to do with a backup, there are still a lot of small websites using ASP
*/
/*************************************** *********************************/
Function template_split ()
{
VaR Len = 0;
VaR arr;
If (this [This. tplname] = NULL) return;
VaR template_exp = This. RegEx;
While (this [This. tplname]. Search (template_exp )! =-1)
{
Arr = This [This. tplname]. Match (template_exp );
For (VAR I = 0; I <arr. length; I ++ ){
Var key = arr [I]. Slice (2,-1 );
Try {
This [This. tplname] = This [This. tplname]. Replace (ARR [I], Eval (key ));
} Catch (Ex ){
This [This. tplname] = This [This. tplname]. Replace (ARR [I], "error:" + ex. Message );
}
}
}
}
Function template_load (filename)
{
Try {
VaR HTTP = server. Createobject ("msxml2.serverxmlhttp ");
HTTP. setoption (2, 13056 );
VaR thishost = request. servervariables ("http_host ");
VaR thisdir = request. servervariables ("path_info"). item;
VaR pathinfo = thisdir. substring (0, thisdir. lastindexof ("/") + 1 );
VaR url = "http: //" + thishost + pathinfo + "template/" + filename;
HTTP. Open ("get", URL, false );
HTTP. Send ();
VaR resp = http. responsetext. Replace ("\ r \ n ","");
// Response. Write (RESP );
This [This. tplname] = resp;
This. Split ();
} Catch (Ex ){
This [This. tplname] = "error: Template read error," + ex. message;
}
}
// Final display
Function template_show (){
Response. Write (this. Content ());
}
Function template_content (){
Return this [This. tplname];
}
/************************************ **********************************/
/*
@ See
usage
var TPL = new template (); // initialize
TPL. load ("index.htm"); // load the template
TPL. show (); // display template
TPL = NULL; // release resources */
/****************************** **************************************** **/
function template (PATH)
{< br>
If (Path = NULL | Path = undefined) Path = "template ";
This. tplpath = path;
This. regEx = new Regexp ("\ $ * \ {* (\ W ** (\ (* ([^)] *? *) * \) {0,}) * \} "," ig ");
This. tplname = "tplcontent"; // The variable name and value cannot be the same, otherwise it will be overwritten
// method
This. split = template_split;
This. load = template_load;
This. show = template_show;
This. content = template_content;
}< BR >%>