Original link:
http://www.cnblogs.com/wysky/archive/2007/12/04/982629.html
Very simple, but finally get out ~
StringTemplate template engine - originally used in the template is written .cs inside, feeling isolated after slow a lot .... estimated to be cached it - do not know better the proposal did not
template page
.aspx page
.cs page
There renderings
StringTemplate template engine - originally used in the template is written .cs inside, feeling isolated after slow a lot .... estimated to be cached it - do not know better the proposal did not
template page
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > $title$ </ title >
</ head >
< body >
$var$
</ body >
</ html >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< title > $title$ </ title >
</ head >
< body >
$var$
</ body >
</ html >
.aspx page
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeBehind
=
"
Default.aspx.cs
"
Inherits
=
"
TemplateTest._Default
"
%>
.cs page
using
System;
using System.Web;
using Antlr.StringTemplate;
using System.IO;
// using Antlr.StringTemplate.Language;
// using antlr.collections;
namespace TemplateTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
StringTemplate st = new StringTemplate(Read( " default.htm " ));
st.SetAttribute( " title " , " 第一个示例 " );
st.SetAttribute( " var " , " Hello World " );
Response.Write(st.ToString());
}
public static string Read( string filename)
{
filename = HttpContext.Current.Server.MapPath( " ~/Template/ " + filename);
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
StreamReader sr = new StreamReader(fs);
return sr.ReadToEnd();
}
}
}
}
using System.Web;
using Antlr.StringTemplate;
using System.IO;
// using Antlr.StringTemplate.Language;
// using antlr.collections;
namespace TemplateTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e)
{
StringTemplate st = new StringTemplate(Read( " default.htm " ));
st.SetAttribute( " title " , " 第一个示例 " );
st.SetAttribute( " var " , " Hello World " );
Response.Write(st.ToString());
}
public static string Read( string filename)
{
filename = HttpContext.Current.Server.MapPath( " ~/Template/ " + filename);
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
StreamReader sr = new StreamReader(fs);
return sr.ReadToEnd();
}
}
}
}
There renderings
Reproduced in: https: //www.cnblogs.com/wysky/archive/2007/12/04/982629.html