Used to use a period of time in PHP, feeling very good, which I remember the most memorable is the Smarty template engine, at that time to think ASP.net have no template engine like this? However, because after the work of the content is not used, or did not think of using a template, the idea did not lead me to do something, it was nothing.
Now is also the job need, with the template is a good choice. Have not used this kind of thing before, blind search a piece did not find oneself want, so oneself try to write, the big idea uses is smarty, use HTML page as template, generate ASPX page, put the data in Httpcontext.items, the code is as follows:
HTML templates:
<div>{$title}</div>
<select>
{foreach $l in $list}
<option value= ' {$l. Age} ' >{$ L.name}</option>
{/foreach}
</select>
Generated aspx page:
<%@ Page language= "C #"%>
<%
if (httpcontext.current.items["Smarty_template_dir"]==null)
{
Response.Write ("No direct access Allowed");
Response.End ();
}
%>
<div><%=dotsmarty.smarty.gettemplatearg ("title")%></div>
<% var list = DOTSMARTY.SMARTY.GETTEMPLATEARG ("list") as system.collections.generic.ilist<smartytest.user>; %>
<select>
<% foreach (var l in list) {%>
<option value= "<%=l.age%>" ><% =l.name%></option>
<%}%>
</select>
Call such as:
Smarty Smarty = new Smarty ();
list<user> list = new list<user> ();
List. ADD (New User () { age=1, name= "name111"});
List. ADD (New User () {age = 2, Name = "name222"});
Smarty. Assign ("title", "caption");
Smarty. Assign ("list", list, templateargtype.list);
Smarty. Display ("user/userinfo.htm");
Looks like smarty, but the more difficult it is to write! Alas, the ability is limited, the future has the ability to say again, now can only give up.
A few days ago I was lucky to hear about Dotliquid, the URL is: http://dotliquidmarkup.org. Above said: "Dotliquid is a templating system ported to the. NET Framework from Ruby ' s liquid markup.it's easy to learn, Fast and safe". I think I finally found the asp.net in the Smarty, but also illustrated: