My web page consists of vertically aligned blocks. Each of these blocks/nodes may have a custom background color or image. I am entering the background color/image within the specific block. How can i then apply these CSS attributes on that specific block? I would like to simply render the block as

<section id="dlazdice" style="background: {{ field.bgr_color }} url('{{ field.bgr_image }}')">

I played with block template but was not able to persuade the color or image attribute to appear where i needed them, both the values were wrapped in the useless

<div class="field".../>



You can do it with this module: https://www.drupal.org/project/bg_image_formatter

Just upload image as background field and set the class in the field settings for which element you want to display image as bgd. It works with Views as well. So, for example, you can use Views conditional module and create a block and test if bdg field is empty and then create different styles with bgd color in that case.

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.