mikebridge / Liquid.NET

.Net Port of the Liquid template language
MIT License
61 stars 15 forks source link

Liquid c# context initialize variable with T type #74

Closed pranavdhundhia closed 5 years ago

pranavdhundhia commented 5 years ago

ITemplateContext ctx = new TemplateContext(); List<Orders> ProductList = new List<Orders> { new Orders {OrderId = 1,ProductName="Some name",Quantity =30}, new Orders {OrderId = 1,ProductName="Some name1",Quantity =30}, new Orders {OrderId = 1,ProductName="Some name2",Quantity =30} }; ctx.DefineLocalVariable("context", new LiquidCollection(ProductList));

Define Liquid Collection with List throws error. Is it possible to define T type generic collection as ITemplateContext-> LocalVariable

pranavdhundhia commented 5 years ago

` ITemplateContext ctx = new TemplateContext(); List ProductList = new List { new Orders {OrderId = 1,ProductName="Some name",Quantity =30}, new Orders {OrderId = 1,ProductName="Some name1",Quantity =30}, new Orders {OrderId = 1,ProductName="Some name2",Quantity =30} };

        ctx.DefineLocalVariable("context", ProductList.ToLiquid());`
pranavdhundhia commented 5 years ago

ctx.DefineLocalVariable("context", ProductList.ToLiquid());

Use using Liquid.NET.Utils;