I am looking for a way to get the url of an image dynamically to put it as a background. So I created a view that get the image field of the node or taxonomy term, which is supposed to output the url only (I have tried only with the node so far). I have been cleaning as much as possible everything inside the view and also the template of the view looks basically like {{rows}} and that's it. But there is still a wrapper div that I can't trim:

<div class="views-element-container form-group">


How can I trim the twig variable created in the theme to get rid of the html tags ?

When I try strip_tags() function in the theme preprocess or |striptags or |trim directly in the template, it's not working and I have a lot of errors starting with Warning: strip_tags() expects parameter 1 to be string, array given in __TwigTemplate for example

1 Answer 1


I found a solution. I was looking at the problem the wrong way. It is possible to get the raw url value of an image field in a page template by using native twig-drupal functions instead of using a view => https://drupal.stackexchange.com/a/224311/16146

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.