I'm trying to make a view for showing latest youtube videos in a block

I have a field called Youtube Video ID (Plain text) where I Drupal 8 stores the ID of the video...

I'm using the option of the field "Override the output of this field with custom text" in REWRITE RESULTS...

I'm doing something like this:

<div class='embed-container-youtube'>
<iframe src='http://www.youtube.com/embed/{{ field_id_video_de_youtube__value }}' frameborder='0' allowfullscreen></iframe>

Like you can see.. I'm using that mark up to show a youtube video.. taking the value of the field....

the problem is that Drupal is cleaning the iframe mark up.. I think for security...

this is how Drupal render it in the website

<div class="embed-container-youtube">


When you configure the content type you can see a note:

Allowed HTML tags: <a> <b> <big> <code> <del> <em> <i> <ins> <pre> <q> <small> <span> <strong> <sub> <sup> <tt> <ol> <ul> <li> <p> <br> <img>
This field supports tokens.

how can I add more allowed tags?

How can I allow that HTML tag for this view? ¡Thanks!

3 Answers 3


I have been wrestling with this as well but my users want to embed google docs. Same concept though.

I figured out the solution and it's not super complicated. You you just need to create a 'Field Template' in the theme.

This video covers the concept with 'Node Template' but you can easily apply it to the field template.

Drupal 8 Theming - Part 11 - Displaying Fields https://www.youtube.com/watch?v=fQ6Ypik_jsE

  • I tried to create an override for the template: core/modules/block/templates/block.html.twig in themes/my_theme/templates/block--views-block--ultimos-videos-block-1.html.twig but I cant print tags like this: {{ content.field_id_video_de_youtube }} The only available tag is {{ content}} Oct 12, 2016 at 15:18

I was able to get around this by including the entire iframe in the field and displaying the field as is. I avoided rewriting it anyway with views, no rewrite results or using a custom text field.

It's not ideal and means more CSS but at least the iframes are in the view.


It's been a while since this question has been asked, but in case someone searches for a solution for this problem and ends up here (like I did):

You can add the iframe-Tag to the Xss whitelist:

  • Open the file core/lib/Drupal/Component/Utility/Xss.php

  • Add 'iframe' to the $adminTags array

After refreshing the cache, iframe-Tags will no longer be stripped from your override text.

  • 4
    Don't do this, it will break next time when you update Drupal.
    – Hudri
    Jun 5, 2019 at 13:37

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.