0


Sorry I'm newbie in drupal 8
I want to render my content from database which have <p> tags inside and my expectation every <p>content</p> will create new paragraph
My database content was like this:

<p>Content 1</p>

<p>Content 2</p>

<p>Content 3<a href="#"></a></p>

I was try using {{ content.value |raw }} but it was render all content without create new paragraph

I also try using {{ content.value | raw | nl2br }} and {{ content.value | replace({"\n": "<br>"}) | raw }} but this one create double <br> every paragraph so my paragraph become annoying

Is there any solution in twig to render <p> tags to create beautifull paragraph?

Thank you

1

1) It's bad security practice to use |raw. See How do I get the raw field value in a twig template? for proper/safe way to do it.

2) I am confident that {{ content.field_name }} or {{ entity.field_name.value }} is printing your <p> tags. If you right click and inspect element, you should see them in the HTML. Your issue must be CSS related perhaps the p { ... } CSS code have an inline or a float in them.

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.