I'm working with Hero slider and views to display slider from nodes in custom type. Where I am now, is:

  • created node type with fields like title, content, picture and background picture,
  • created views for dysplay this content, hide all fields, last one is background field, in this field i wrote rewrite twig code do dysplay all fields with some if function to choose prefered slide type and display content right way in every slide,
  • what I need is make wrap around every li element with slide content, because views filter out markup, and I can't get slide with responsive background.. life would so much easier with that filter go away.
  • I work with views-view-field--slider.html.twig that is displayed correct from my template.
  • I cant display my link to image for background in code:
<div style="background-image: url( {{ HERE IS MY PROBLEM }} )">{{ output -}}</div>

I feel lost with data = row[field.field_alias] tried kint, dump and a lot of various combination of twig code.. looks like I am missing some basics or simple target code to this field. Help me..

1 Answer 1


Ok, so how I solved it... Maybe there is other, better solution?

  1. I rearrangement my fields in view: first with content, title, pictures and links,
  2. I've added one more custom text field with rewrite - then I put in this rewrtite all fields above with some twig function to display this in different ways and hide this field to.
  3. Then I've added last field, field_background which is one with slide background picture. I turn it to display just URL of picture and write rewrite inside to display:

    {{ field_background }} )"> {{ nothing }}

wher nothing is my field with all content stuf inside.

  1. I've edited twig template for last field and write something like this:

    <.div style="background-image: url( {{ output }}

so when views start rendering content it create code from my last field which is wrapprer with background image around content form other fields above.

Well, it's work, my slides run with background picture. But I dont fell good with that, I think there is better way to get it in one field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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