I have a data source like this:
School {
Id,
Name,
City,
TeacherComments,
Teacher {
Id,
Person {
Id,
Name,
Address
}
},
StaffComments,
Staff {
Id,
Person {
Id,
Name,
Address
}
}
}
Then my template is like this:
test.docx (27.6 KB)
When I create the report, I get the error: Error! A band end is not expected. after the <</foreach>>
in the Teacher details column.
What can I do to fix this error?
@gregEsg There are several mistakes in the syntax in your tempalte:
<[school.Name]>>
must be <<[school.Name]>>
<<foreach [teacher in school.Teachers>>
must be <<foreach [teacher in school.Teachers]>>
<<foreach [staff in school.Staff>>
must be <<foreach [staff in school.Staff]>>
Here is the modified template: in.docx (27.9 KB)
Here is code I used for testing:
public class School
{
public string Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string Sequence { get; set; }
public string TeacherComments { get; set; }
public string StaffComments { get; set; }
public List<Teacher> Teachers = new List<Teacher>();
public List<Staff> Staff = new List<Staff>();
}
public class Teacher
{
public string Id { get; set; }
public Person Person { get; set; }
}
public class Staff
{
public string Id { get; set; }
public Person Person { get; set; }
}
public class Person
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
School school = new School() { Id = "S1", Name = "Cool School", Sequence = "test", City = "Kharkiv", TeacherComments = "Some Teacher Comments", StaffComments = "Some Staff Comments" };
school.Teachers.Add(new Teacher() { Id = "T1", Person = new Person() { Id = "P1", Name = "Alexey", Address = "Kharkiv" } });
school.Teachers.Add(new Teacher() { Id = "T2", Person = new Person() { Id = "P2", Name = "James Bond", Address = "London" } });
school.Staff.Add(new Staff() { Id = "ST1", Person = new Person() { Id = "P3", Name = "John Dou", Address = "Unknown" } });
school.Staff.Add(new Staff() { Id = "ST2", Person = new Person() { Id = "P4", Name = "Jane Dou", Address = "Unknown" } });
List<School> schools = new List<School> { school };
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, schools, "Schools");
doc.Save(@"C:\Temp\out.docx");
Here is the produced output: out.docx (21.9 KB)
Thank you for the quick reply. I also noticed the syntax errors, but forgot to re-upload. And I’m still getting the same error after fixing them. Could you test again with multiple schools to make sure that’s not a problem? I will do some more testing on my side to see if I can figure it out as well.
Edit: I found the problem. I had simplified the example template to make it simpler to post, and in doing so, I removed the error in the uploaded template.
The problem was inside the teacher foreach
. There was an opening if
tag that was missing the closing tag. I was confused because of the position and wording of the error, since it suggests that the problem is with the foreach
. Thank you for the help.
1 Like
@gregEsg It is perfect that you managed to resolve the problem. Please feel free to ask in case of any further issue, we are always glad to help you.