+1 vote

If I had a template using .DataFrom(obj) that looked like this

Hello, my name is [Name]

I have the following children

[foreach Children]
    [Name <reference the parent object>] has child named [ChildName].
[end]

How do I reference the parent object inside a foreach loop?

Thanks

by

1 Answer

0 votes

This is not possible, unless your child object exposes its parent as a property.

class Parent
{
    public string Name { get; set; }
    public List<Child> Children { get; set; }
}

class Child
{
    public Parent Parent { get; set; }
}

In the template you can use Parent property now:

Hello, my name is [Name]

I have the following children

[foreach Children]
    [Parent.Name] has child named [ChildName].
[end]
by (297k points)
...