开发者

How do I pass an array to a template and then show the content in Play Framework?

开发者 https://www.devze.com 2023-03-26 04:45 出处:网络
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.

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:

&开发者_JS百科lt;html>
<body>
<h1>Users</h1>

<ul>
    #{list users:users, as:'user' }
        </li>${user.name}</li>
    #{/list}
</ul>

</body>
</html>


The list tag takes either an items parameter 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'}.

0

精彩评论

暂无评论...
验证码 换一张
取 消