DotLiquid Looping

63 views
Skip to first unread message

Asad Gilani

unread,
Jun 10, 2020, 7:53:07 AM6/10/20
to dotliquid
@All :

I am newbie for the DotLiquid.I tried the first example from the http://dotliquidmarkup.org/try-online

using DotLiquid;
using DotLiquid.NamingConventions;
using System;
using System.Collections.Generic;

public class User : Drop
{
    public string Name { get; set; }
    public List<Task> Tasks { get; set; }
}

public class Task
{
    public string Name { get; set; }
}
namespace TestDotLiquidLoop
{

    
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            
            //const string template1 = "{{ user.name | upcase }} has to do:{% for item in user.tasks -%}{ { item.name } }{% endfor -%}";
            const string template = "<p>{{ user.name | upcase }} has to do:</p>" +
                "< ul >{% for item in user.tasks -%}" +
                "< li >{ { item.name } }</ li >" +
                "{% endfor -%}" +
                "</ ul > ";
            Template preparedTemplate = Template.Parse(template);


            var user = new User
            {
                Name = "Tim Jones",
                Tasks = new List<Task>
            {
                new Task { Name = "Documentation" },
                new Task { Name = "Code comments" }
            }
            };
            Console.WriteLine(preparedTemplate.Render(DotLiquid.Hash.FromAnonymousObject(new { usertemp = user })));
            
        }
    }
}


I know I am doing some mistake in DotLiquid.Hash.FromAnonymousObject(new { usertemp = user }) in this line. I am really stuck at this point.
Any help will be appreciated.

Best Regards

David Burg

unread,
Jun 14, 2020, 2:36:03 PM6/14/20
to dotl...@googlegroups.com

I believe Task class has to inherit Drop as well.

 

With regards,

 

David.

--
You received this message because you are subscribed to the Google Groups "dotliquid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotliquid+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotliquid/fe82511f-28c2-4c0f-9759-31d32747d1b6o%40googlegroups.com.

Asad Gilani

unread,
Jun 14, 2020, 3:29:37 PM6/14/20
to dotl...@googlegroups.com
@David: Thanks for your reply.
The problem is solved for me.I already implemented the Drop. There was some mistake while creating the anonymous object and assigning to the variable.

Thanks for your help.

David Burg

unread,
Jun 14, 2020, 3:31:00 PM6/14/20
to dotl...@googlegroups.com

If you can share your working sample on GitHub it could be of help to the next engineer ramping up on DotLiquid.

 

Cheers,

Reply all
Reply to author
Forward
0 new messages