How to add background in Drupal 8 views-view-fields.html.twig' files.
I try like this but it's don't work. Using views I just output image paht.
<div class="cover-img" style="background:url('{{ field_image }}');">
</div>
Thank you
How to add background in Drupal 8 views-view-fields.html.twig' files.
I try like this but it's don't work. Using views I just output image paht.
<div class="cover-img" style="background:url('{{ field_image }}');">
</div>
Thank you
Adding CSS background image hardcoded in the Twig (or TPL in D7 sites) isn't a best practice. You should do this via your theme's css file like style.css
, or via a module (some theme's give you the opportunity to add it directly on your site).
I would suggest to restore any such changes in the Twig and redoing it in the css file.
Download Image URL Formatter module
This module add a url formatter for image field. Then you can output image url directly.
Once enabled, views will give you an option to change the formatter to url when you edit or add your image field.
After you select url as your formatter, {{ field_image }}
will output url instead of picture.