How do you enable a user to upload a css background Image?

Do you write some inline css in the page header with twig markup? Do you write some twig markup inside a css file?

Or do you fake a background image by add an image and then position it absolute?

What's the best practice there?


You can simply add it inline to your body tag like so:

<body style="background-image: url({{ myGlobal.myAssetsField.first().url }})">

If you want to only use it with selected templates, you'd better use Craft's includeCss tag:

{% set bodyCss %}
    .myBodyClass {
        background-image: url({{ myGlobal.myAssetsField.first().url }});
{% endset %}

{% includeCss bodyCss %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.