Use image from shared folder

I am trying to set as background the image located in /public/images/my-image.jpg

I tried

<body background="public/images/my-image.jpg">

and

<body background="images/my-image.jpg">

and

<body background="my-image.jpg">

But I always get 404 (Not Found)on the Chrome console. Any idea why?

I also tried adding this:

<style>
    body {
        background-image: url("/public/images/my-image.jpg");
    }
</style>

But nothing is displayed on the background of the page.

+4
source share
3 answers

As I understand it, you have problems getting assets in playframework. Follow the documentation for the framework for assets .

( ), assets/ public/. . 2.5x :

<body background="@routes.Assets.versioned("images/my-image.jpg")">

<body background="assets/images/my-image.jpg">

.

+1

, HTML5, css, body { background-image: url("gradient_bg.png"); }

font: https://www.w3schools.com/tags/att_body_background.asp

+1

routes

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

public :

<body background="@routes.Assets.versioned("images/my-image.jpg")">

<body background="/assets/images/my-image.jpg")">

.

If you want to change the “assets” to “public” or any other , just change it in the file routes:

GET     /public/*file               controllers.Assets.versioned(path="/public", file: Asset)

Then your assets will be available along the way public, for example:

<body background="/public/images/my-image.jpg")">

However, it @routes.Assets.versionedwill be the same:

<body background="@routes.Assets.versioned("images/my-image.jpg")">

That is why it @routes.Assets.versionedis the preferred method.

+1
source

Source: https://habr.com/ru/post/1671930/


All Articles