I'm attempting to display a plain text field so that I can use it to embed youtube videos

In my template I have

<iframe width="420" height="315" src="https://www.youtube.com/embed/{{ content.field_video }}" frameborder="0" allowfullscreen></iframe>

However when it renders it produces a mess

<iframe width="420" height="315" src="https://www.youtube.com/embed/&#10;&#10;&lt;!-- THEME DEBUG --&gt;&#10;&lt;!-- THEME HOOK: 'field' --&gt;&#10;&lt;!-- FILE NAME SUGGESTIONS:&#10;   * field--node--field-video--beer.html.twig&#10;   * field--node--field-video.html.twig&#10;   * field--node--beer.html.twig&#10;   * field--field-video.html.twig&#10;   * field--string.html.twig&#10;   x field.html.twig&#10;--&gt;&#10;&lt;!-- BEGIN OUTPUT from 'core/themes/stable/templates/field/field.html.twig' --&gt;&#10;&#10;            &lt;div data-quickedit-field-id=" node="" 15="" field_video="" en="" full"="">C0DPdy98e4c&lt;/div&gt;

&lt;!-- END OUTPUT from 'core/themes/stable/templates/field/field.html.twig' --&gt;

" frameborder="0" allowfullscreen&gt;</iframe>

I understand that part of it is because I'm in debug mode, but it's also wrapping it in a quick edit field div. And even if it didn't I'd rather not exit debug mode just to work on this. Is there a way to output just the value and nothing more? Like something similar to {{ content.field_video.value }}?

If I can't disable quick edit field by field, is there a way to print a field while keeping the HTML intact? When I put the entire iframe into field it turns the html tags into text.

I tried

{{ content.field_video|raw }}

but the output still showed the html tags as text. I tried

{{ content.field_video.value|raw }}

But that did not show anything.


I was able to print the value by using

{{ content.field_video[0] }}
  • 1
    Did the above worked in debug mode? – No Sssweat Jul 1 '16 at 4:38
  • 1
    yes it did. It only printed the value, none of the surrounding debug info. – Matt Jul 1 '16 at 15:52

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.