Play! Framework render template shortcut

Sometimes you want to render directly to a known template from a controller.

To do this you can use the documented method renderTemplate(String templateName, Object[] args)

Doing so requires that the first parameter be the complete path to the template.
renderTemplate("Registration/signup.html", user)

But there is a shortcut that allows you to use the “@” symbol with the fully qualified class and method.

renderTemplate("@Registration.signup", user) or render("@Registration.signup", user) which gets expanded to "Registration/signup.html".

And if the template exists in the same Controller you can omit the class and simply use the method name.

render("@signup", user) which is expanded to "Registration/signup.html" if called from the Registration controller.

This entry was posted in Play framework. Bookmark the permalink.

1 Response to Play! Framework render template shortcut

  1. opensas says:

    nice shortcut indeed, I saw it in a couple of examples, but couldn’t find it anywhere on the docs…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s