Reputation: 9498
I'm using Play 2.4 (Java version) but I'm also interested in solutions for >2.4. This is my problem. I want to structure the content of my template folder under app/views. So I'd like to create some sub packages under app/views but get compilation errors. Here is, what I've tried so far:
Create new subpackage via eclipse
app/views/mediaViewers
Put a template standardViewer.scala.html
in it
app/views/mediaViewers/standardViewer.scala.html
Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Rebuild play project
activator clean; activator clean-files; activator run
When calling the appropriate route I get:
[error] .../Viewers.java:18: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] ..../Viewers.java:21: package views.mediaViewers.html does not exist
[error] views.mediaViewers.html.standardViewer
[error] .../app/controllers/Viewers.java:24: package views.mediaViewers.html does not exist
...
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application -
! @765kicfe1 - Internal server error, for (GET) [/] ->
play.sbt.PlayExceptions$CompilationException: Compilation error[package views.mediaViewers.html does not exist]
...
Upvotes: 1
Views: 278
Reputation: 186
In order to call a view template from the controller you should alwayes prefix the name of the view with "views.html", so the call to standardViewer.scala.html would be :
views.html.mediaViewers.standardViewer
you can verify this if you took a look at the generated files under target/scala-/twirl as indicated in this picture : project structure
Upvotes: 2
Reputation: 9498
The package path in the controller is wrong! Use this pattern:
`views.html.your-package-goes-here.your-template-goes-here.render()`
Or more concrete:
- Try to access the template from controller class via
views.mediaViewers.html.standardViewer.render()
Has to be:
views.html.mediaViewers.standardViewer.render()
Upvotes: 1