I'm trying to make a route to a specific static file but everything I'm trying ends with an error.
I've made 3 different attempts:
1.
GET /file staticFile:/public/html/file.html
The error I get:
Compilation error string matching regex `\z' expected but `:' found
2.
GET /file controllers.Assets.at(path="/public/html", "file.html")
The error I get:
Compilation error Identifier expected
3.
GET /file controllers.Assets.at(path="/public/html", file="file.html")
The error I get: (and this is the weirdest)
Compilation error not enough arguments for method at: (path: String, file: String)play.api.mvc.Call. Unspecified value parameter file.
The weird part about the 3rd error is that it's thrown in a different file (app/views/main.scala.html) on the following line:
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
All of these methods were found in the official documentation and/or threads here on stackoverflow. What am I missing here?
Thanks.
IIRC, change
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
To
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/", "main.css")">
I am talking about your third attempt
Also, watch out for extra /
EDIT
GET /assets/main.css controllers.Assets.at(path="/public", file="/stylesheets/main.css")
Assuming your resource is at /public/stylesheets/main.css
I am not totally sure if this is correct, but this is what we are using to map a public folder containing our images, javascripts... etc..
# Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With