asp.Netテンプレートエンジン:C#でのNvelocityの簡単な使用
2118 ワード
using
NVelocity;
using
NVelocity.App;
using
NVelocity.Runtime;
/*
*
*/
VelocityEngine vlte =
new
VelocityEngine();
vlte.SetProperty(RuntimeConstants.RESOURCE_LOADER,
"file"
);
vlte.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,Server.MapPath(
"~/"
));
vlte.Init();
/*
*
*/
VelocityContext vlc =
new
VelocityContext();
vlc.Put(
"Name"
,
" "
);
vlc.Put(
"Age"
,
"24"
);
/*
*
*/
Template vtp = vlte.GetTemplate(
"Model.htm"
);
StringWriter str =
new
StringWriter();
vtp.Merge(vlc, str);
Response.Write(str.GetStringBuilder().ToString());