Yunfei Xue
Yunfei Xue

Reputation: 23

play framework use image not in /public folder

in play framework I want to show an image not in the /public folder, for the images in the /public folder I can write:

<th><img class="ui" src="@routes.Assets.at("images/ui_iron.png")"/></th>

and put the image in the /public/image folder,but how can I use images not in the public folder,I Tried like this but not work:

GET        /configimage/*file                          controllers.Assets.at(path="../data/public",file)

or I should new a function like controllers.Assets.at

Upvotes: 2

Views: 1370

Answers (1)

Jonas Anso
Jonas Anso

Reputation: 2067

If your goal is just to be able to show images outside public folder you have 2 options:

Add a unmanaged resource in your build.sbt

unmanagedResourceDirectories in Assets += baseDirectory.value / "data"

No need to change the routes files, as all the files inside data will be merged into the public directory during compilation.

You can define different routes for different groups of assets but if you do that in your html file you will need to pass 2 arguments to the Assets.at method one for the path in the routes and one for the file.

Reference

Create your own controller if the images are not part of the project

As in Asset mapping outside public folder on Play framework

Upvotes: 4

Related Questions