How to have a css background-image from form field?

Hi there, I’m one of those guys who come from wordpress to grav without a very big coding knowledge. So far everything works fine with my own bootstrap theme and I already was able to get content from form fields in the backend and show it on the frontend (via blueprints).

One thing is absolutely not possible for my noncoder-brain: how can I show uploaded images in the frontend and especially retrieve the chosen image and use it as a background-image for a div-container per css? I managed to show a pagemediaselect field in the backend but can’t figure out how to use the chosen picture in the css.

Could anyone help me out?

Thank’s in advance and have a nice day!

You will need to modify the template twig file in order to get the image and use inline css to declare background, something like this:

{% set bg_img_url=page.media['yourimagename.jpg'].url() %}

<div style="background image: url('bg_img_url')"></div>

And in blueprint you use type: pagemediaselect to pic one of the uploaded medias. Then display it with twig, and include the .url() to retrieve the url ^^

Okay, so as i really just want to set up a server alias for the subdomain and i’m a very stubborn fellow i looted some more and found this:

#1.part redirect / to index.php otherwise the rule would be "" nothing
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} !rew=1 
RewriteCond %{REQUEST_URI} ^/$ 
RewriteRule ^(.*)$ index.php?rew=1 [QSA,L,NE]

#2.part remove / from begin of the request, then silent redirect there
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING} !rew=1 
RewriteCond %{REQUEST_URI} ^/(.*)$ 
RewriteRule ^(.*)$ %1?rew=1 [QSA,L,NE]

It is for htaccess ofc.
It works for main page tho have not yet tested it allot!

Damn, wrong thread :wink: