2

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.

2 Answers 2

1

I was able to print the value by using

{{ content.field_video[0] }}
3
  • 1
    Did the above worked in debug mode?
    – No Sssweat
    Jul 1, 2016 at 4:38
  • 1
    yes it did. It only printed the value, none of the surrounding debug info.
    – Amy
    Jul 1, 2016 at 15:52
  • Sadly, in my use case, this just gets me a NULL. MAybe because it's D9, or a different content type
    – Mir
    Jul 25, 2022 at 22:06
0

I ended up needing to use

fields.field_name.content|striptags|trim

but this was inside a views-view-field--view-name.html.twig template... so it might be a different use case. Drupal 9. Media oembed video content type.

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.