0

Using the following code for displaying content from a WYSIWYG field: content.field_body|raw I only got the text without images added in a editor as media. When I remove filter raw I see <drupal-entity data-embed-button="media_browser" data-entity-embed.... is being displayed as a text but not as image.

  • This happens in paragraph, I forgot to mention. – master Mar 20 '17 at 15:02
  • probably the text filter for embedded media is missing, check if "Display embedded entities" is checked in the text format configuration – 4k4 Mar 20 '17 at 15:08
  • "Display embedded entities" is checked in rich text configuration. – master Mar 20 '17 at 15:12
  • then you need to make sure that the text format is applied to the field, it seems it is not – 4k4 Mar 20 '17 at 15:17
  • @4k4 how can I check that? – master Mar 20 '17 at 15:29
4

This output from the body field

<drupal-entity data-embed-button="media_browser" data-entity-embed....

is the raw data stored in the database. The tag <drupal-entity> gets replaced by the text filter "Display embedded entities" when the field is rendered.

If you access the field data directly from the entity #paragraph you bypass this rendering process.

Instead of the raw filter, which doesn't help in any way, it only makes your site vulnerable to the content of the body field, you can apply the text format in a render element processed_text:

  {% set paragraph =  content.field_tabs.0['#paragraph'] %}

  {% set body = {
    '#type':   'processed_text',
    '#text':    paragraph.field_body.value,
    '#format':  paragraph.field_body.format,
  } %}

  {{ body }}
  • Right/Perfect/Satisfying approach and the Drupal way! – Vishal Kumar Sahu Feb 12 at 13:30

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.