diff --git a/app/controllers/HomeController.scala b/app/controllers/HomeController.scala index 7a79ee35..e6af3d5d 100644 --- a/app/controllers/HomeController.scala +++ b/app/controllers/HomeController.scala @@ -1,6 +1,7 @@ package controllers import javax.inject._ + import play.api.mvc._ /** @@ -8,7 +9,8 @@ import play.api.mvc._ * application's home page. */ @Singleton -class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { +class HomeController @Inject()(cc: ControllerComponents) (implicit assetsFinder: AssetsFinder) + extends AbstractController(cc) { /** * Create an Action to render an HTML page with a welcome message. diff --git a/app/views/index.scala.html b/app/views/index.scala.html index 604eceba..d2884300 100644 --- a/app/views/index.scala.html +++ b/app/views/index.scala.html @@ -1,15 +1,15 @@ @* - * This template takes a single argument, a String containing a - * message to display. + * This template takes a two arguments, a String containing a + * message to display and an AssetsFinder to locate static assets. *@ -@(message: String) +@(message: String)(implicit assetsFinder: AssetsFinder) @* * Call the `main` template with two arguments. The first * argument is a `String` with the title of the page, the second * argument is an `Html` object containing the body of the page. *@ -@main("Welcome to Play") { +@main("Welcome to Play", assetsFinder) { @* * Get an `Html` object by calling the built-in Play welcome diff --git a/app/views/main.scala.html b/app/views/main.scala.html index 9414f4be..2351072f 100644 --- a/app/views/main.scala.html +++ b/app/views/main.scala.html @@ -1,19 +1,20 @@ @* * This template is called from the `index` template. This template * handles the rendering of the page header and body tags. It takes - * two arguments, a `String` for the title of the page and an `Html` - * object to insert into the body of the page. + * three arguments, a `String` for the title of the page and an `Html` + * object to insert into the body of the page and an `AssetFinder` + * to define to reverse route static assets. *@ -@(title: String)(content: Html) +@(title: String, assetsFinder: AssetsFinder)(content: Html) @* Here's where we render the page title `String`. *@ @title - - - + + + @* And here's where we render the `Html` object containing diff --git a/conf/application.conf b/conf/application.conf index 8f313149..c184259d 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -347,3 +347,12 @@ db { # https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements #default.logSql=true } + +## Static assets +# Using configuration and assets finder +# https://www.playframework.com/documentation/latest/AssetsOverview +# Since +play.assets { + path = "/public" + urlPrefix = "/assets" +} \ No newline at end of file diff --git a/conf/routes b/conf/routes index cc707d49..706aea95 100644 --- a/conf/routes +++ b/conf/routes @@ -10,4 +10,4 @@ GET /count controllers.CountController.count GET /message controllers.AsyncController.message # Map static resources from the /public folder to the /assets URL path -GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) +GET /assets/*file controllers.Assets.versioned(file)