0

I have the following Blade template code:

<p>{!! $description !!}</p>

The current output is:


<p></p>
<h1>This is a heading</h1>
<p>This is a paragraph</p>

I've also tried using the following approaches, but they didn't give me the desired result:

{!! html_entity_decode($description) !!}
{!! nl2br($description) !!}

However, I'd like the content within the tags to be placed inside a paragraph. How can I achieve this output?

Is there a way to properly structure the Blade template code so that the entire content, including headings and paragraphs, is wrapped inside the opening and closing

tags?

adil
  • 43
  • 1
  • 8
  • That is not the current output. That is what your browser's DOM inspector makes of the current output, which is invalid HTML. (View source to see the actual output, which is as you expect it.) You can't put an `h1` element inside a `p` element. – miken32 Aug 02 '23 at 17:21
  • @miken32 I don't have control over the content inside the **$description**. So what you are saying I need to change my HTML ??? – adil Aug 02 '23 at 17:31
  • 1
    A `p` element can only contain inline elements; if you try to put block elements in, it will not work. So if you want to put block elements in, yes you need to change your HTML. – miken32 Aug 02 '23 at 17:33
  • 1
    A `div` or `section` element would be a better choice. – miken32 Aug 02 '23 at 17:50
  • @miken32 I greatly appreciate your assistance, and I am truly thankful for the guidance provided. – adil Aug 02 '23 at 22:17

0 Answers0