In Playframework2, how do I serve multiple asset directories?

There are two resource directories: one - /ui/distand the other - /public. I tried to write the routes as follows:

GET            /assets/*file                        controllers.Assets.at(path="/public", file)
GET     /ui/*file               controllers.Assets.at(path="/ui/dist", file)

But when compiling it gives an error:

[error] Unspecified value parameter file.
[error]         <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">

Does anyone have any ideas on how to solve this ...

+4
source share
2 answers

I found that the key should pass another parameter routes.Assets.atfrom the playframework asset document file

GET  /javascripts/*file        Assets.at("public/javascripts", file)
GET  /images/*file             Assets.at("public/images", file)

Then you will need to specify both parameters when using a reverse router:

<script src="@routes.Assets.at("public/javascripts", "jquery.js")"></script>
<image src="@routes.Assets.at("public/images", "logo.png")">
+2
source

Try creating a separate router object for each of them:

package controllers

object PublicAssets extends controllers.AssetsBuilder
object UiDistAssets extends controllers.AssetsBuilder

:

GET     /assets/*file   controllers.PublicAssets.at(path="/public", file)
GET     /ui/*file       controllers.UiDistAssets.at(path="/ui/dist", file)

, , , ui, ( - , , .) , -, (, , , .)

0

All Articles