Syntax to link to an image as background-image property in October CMS

967 views Asked by At

I've tried using the Ocober CMS syntax and relative URL in linking to an image in CSS background-image property. Please how do I achieve this. Code looks like

style="background-image: url('/assets/img/h2.jpg');"

I'm trying to this from a page file.

3

There are 3 answers

0
Sagar Gautam On

Change your code like this,

style="background-image: url({{asset('/assets/img/h2.jpg')}});"

You need full path of the image so asset will add the path up to public directory and then further location will be added.

I hope you understand.

0
Zakir hussain On

Put the image in assets/img folder(create a new folder if it is not there) of your theme and link the image with that path.

you can call in your .htm file like that

style="background-image: url({{ 'assets/img/h2.jpg'|theme }});"
0
EranGrin On

If you're trying to do the background image cover responsive trick and still don't see any img, you might need to add

height: 100%;

for example,

<div style="height: 100%; background-size: cover; background-image: url({{ 'my-img.jpg'|media }});"></div>

that solve the issue for me