请考虑这个课程:
var dep =
new Department
{
Name = "Jack",
Employees = new List<Employee>
{
new Employee()
{
Name = "E1",
Kids = new List<Kid>()
{
new Kid
{
Name = "K1"
},
new Kid
{
Name = "K2"
},
new Kid
{
Name = "K3"
},
new Kid
{
Name = "K4"
}
}
},
new Employee()
{
Name = "E2",
Kids = new List<Kid>()
{
new Kid
{
Name = "K5"
},
new Kid
{
Name = "K6"
}
}
},
new Employee()
{
Name = "E3",
Kids = new List<Kid>()
{
new Kid
{
Name = "K7"
}
}
}
}
};
所以我需要定义子模板,如:
{{ Name }}
{% for e in Employee %}
{{ EmployeeTemplate e }} // a Template can be an object for itself as input
{% endfor %}
EmployeeTemplate :
{% for k in Kids %}
{{ KidTemplate k }}
{% endfor %}
KidTemplate :
{% for o in OBJECT %}
{{Name}}
{% endfor %}
和结果:
Jack
E1
K1
K2
K3
K4
E2
K5
K6
E3
K7
我需要模板作为独立的字符串块,所以我想知道dotliquid支持与否? 如果独立模板支持那么我们可以定义嵌套模板吗?