今天写一篇技术文章,关于TemplateEngine的。

时间:2021-08-17 14:37:17

这个模板引擎还算不错,对于asp.net的分层架构还是很有帮助的。现在都流行mvc模式。可以研究一下。

1、foreach,其实重要的就是循环,很多地方都有用到。

<ad:foreach collection="#collection#" var="cust" index="i">
    #cust.lastname#, #cust.firstname# <br />
</ad:foreach>

模板是这样的,那么代码如下

 

TemplateManager template = TemplateManager.FromString(Res.c1);

ArrayList list = new ArrayList();
list.Add(new customer("Tom" , "Whatever"));
list.Add(new customer("Henry" , "III"));
list.Add(new customer("Tom" , "Jackson"));
template.SetValue("collection" , list);


string html = template.Process();

这样就生成了html。

更多的帮助文档可以看看这里:http://www.codeproject.com/Articles/8141/Ader-Template-Engine#xx2238055xx