About the Dotliquid-asp.net template engine

Source: Internet
Author: User
Tags foreach html page httpcontext smarty template

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.