Previously I have only used the Scala templates, but now am I using Java and the Groovy templates. I find it hard to understand the Groovy templates.
I pass an array from my controller to the view like this:
UserRecord[] users = {new UserRecord(1,"Jonas"), new UserRecord(2,"Anders")};
render(users);
Now, how to I create a Groovy template that receives the array and then print them in a list?
I have tried with the code below, but it doesn’t work, no users are listed:
<html>
<body>
<h1>Users</h1>
<ul>
#{list users:users, as:'user' }
</li>${user.name}</li>
#{/list}
</ul>
</body>
</html>
The
listtag takes either anitemsparameter to specify what to iterate over, or the first positional argument.So
#{list users:users, as:'user'}should be either#{list items:users, as:'user'}or just#{list users, as:'user'}.