您的位置:首页 > 产品设计 > UI/UE

.net模版引擎-DotLiquid使用

2013-05-20 17:49 921 查看
Dotliquid是我新进发现的一个用于.net项目的模板引擎,感觉还不错,使用比较简单,功能非常强大。有兴趣的可以看看https://github.com/formosatek/dotliquid,这里写了2个小例子,大家可以先看看

{{name.Nick}}


对应的解析代码如下

public class DotLiquidController : Controller
{
//
// GET: /DotLiquid/
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DotLiquidDemo1(string template)
{
ViewData["template"] = Template.Parse(template).Render(Hash.FromAnonymousObject(new { name =new StudentDrop( new Student() { Nick = "chenlei" } )}));
return View();
}

public ActionResult DotLiquidDemo1()
{

return View();
}
}

public class Student
{
public string Nick
{
get;
set;
}

}

public class StudentDrop :Drop
{
private readonly Student student;

public string Nick
{
get {return student.Nick;}
}

public StudentDrop(Student studentPara)
{
student = studentPara;
}
}


{% for item in name %}
{{ item.Nick }}
{% endfor %}


对应的代码如下:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DotLiquidDemo1(string template)
{
ViewData["template"] = Template.Parse(template).Render(Hash.FromAnonymousObject(new { name =new List<StudentDrop>(){ new StudentDrop( new Student() { Nick = "chenlei" } )}}));
return View();
}

public ActionResult DotLiquidDemo1()
{

return View();
}
}

public class Student
{
public string Nick
{
get;
set;
}

}

public class StudentDrop :Drop
{
private readonly Student student;

public string Nick
{
get {return student.Nick;}
}

public StudentDrop(Student studentPara)
{
student = studentPara;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: