-1

In my content type, I have a text field that will display a string (max 200 characters) in a Bootstrap card. Due to the design, we have to allow the user to add a < br /> or \ n to add "invisible lines" to ensure content is wrapped correctly in the card.

By adding "< br /> to the field however, in twig, the < br /> is printed to screen and not HTML rendered. I have tried:

<p>{{content.field_copy}}</p>    
<p>{{content.field_copy|raw}}</p>
<p>{{content.field_copy|render}}</p>

With no affect. What other options do I have? Can this be done using a text field?

1
  • 2
    For this use case Drupal has an entire ecosystem with formatted text fields, text formats and text filters. Don't try to do this on your own. There are a lot of security considerations.
    – 4uk4
    Commented Feb 23, 2022 at 13:21

1 Answer 1

0

it's bad practice, but still

{{ content.field_copy.0['#context'].value|raw }}
1
  • This is not only bad practice, this is extremely dangerous. Drupal stores user input as it is in the database and the security of a Drupal site relies on that it is not displayed without sanitizing.
    – 4uk4
    Commented Feb 23, 2022 at 20:35

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.