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?
This solution is from the developer of the dotliquid (I posted the same question on the issues list of the github project)
dotliquid uses the ruby convention by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With