As far as I know, Google Closure Template doesn't allow passing Java object into the template (as compared to FreeMarker). So I can't really do something like:
// Java file
class Course {
...
public function getName() {
return name;
}
}
// Main function
public static void main(String args[]) {
// Get all courses
List<Course> courses = Courses.getAllCourses();
Map<String, Object> params = new HashMap<String, Object>();
params.put("courses", courses);
String out = tofu.newRenderer("template.listCourses").setData(params);
}
// Soy file
/**
* @param courses List of courses
*/
{template .listCourses}
Courses List! <br/>
{foreach $course in $courses}
New Course: {$course.name}
{/foreach}
{/template}
I'm thinking if I want to do this I probably have to write a custom function that uses Reflection to turn Course object into a Map? I'm not experienced with Java Reflection. Is there such a function available?