I have created a dotLiquid template with two nested for loop
{% for item in page.Fields %}
<li>
{{ item.Name }}:
<select>
{% for list in item.ListValues %}
<option>{{ list.Text }} </option>
{% endfor %}
</select>
</li>
{% endfor %}
With the following class:
public class Page: Drop
{
public string Name { get; set; }
public List<Field> Fields { get; set; }
}
public class Field : Drop
{
public string Name { get; set; }
public List<ListValue> ListValues { get; set; }
}
public class ListValue : Drop
{
public string Text { get; set; }
}
Then I created an object and ran it like this:
page = MyPage; // This is the created object
Template template = Template.Parse(LiquidTemplate);
string output = template.Render(Hash.FromAnonymousObject(new { page = this.page }));
The object is populated as:
new Page
{
Name = "My Page",
Fields = new List<Field>
{
new Field
{
Name = "Title",
ListValues = new List<ListValue>()
},
new Field
{
Name = "Status",
ListValues = new List<ListValue>
{
new ListValue
{
Text = "Open"
}
}
}
}
};
The inner for loop is not getting populated, even though the object is just fine. I see a lot of empty inner loop <option>
tags...
I have just started with dotLiquid, what am I doing wrong?