How to View New Lines in Database Fields

If you have a database field with new line characters in it (rather than <br> or <p>), the new lines are ignored if you display the database field using this form:

<p>{{field_name}}</p>

This will show:

Line 1 Line 2 Line 3

But they are shown if you display the database field using this form:

<p dmx-text="field_name"></p>

This will show:

Line 1 
Line 2 
LIne 3
1 Like

If you have html code stored in your database table and you want to use it on the page then you need to use the Inner HTML attribute.

Indeed! :slight_smile:

In my example, the content in the database was created using a textarea element which inserts new line characters, rather than a summernote element which inserts <br> and <p>.

So what is your question here exactly? Is it not working with Inner HTML or is your issue something else?

There is no question. This is the answer to a problem I just had!

I created database content with a textarea and then tried to display it with <p>{{field_name}}</p> and the new lines were missing…

So the answer I discovered is here for everyone else to find…

You posted this in the how to section, which is used to ask how to … do some stuff. So i thought you have problems doing what you were trying to do…
And as i explained the purpose of Inner HTML is exactly this.

Yes, this is the answer about "How To" do something!

Sorry Antony, i just probably don’t understand the point of this topic. Hope others will.

I am sure they will! :slight_smile:

The point is if you create database content with a textarea and then try to display it with <p>{{field_name}}</p> then the new line characters will not be displayed!

Of course they won't be displayed Antony!
That is why we have created a special dynamic attribute called Inner HTML which will render your HTML on the page ...

Well it may be "Of course" to you, but it wasn't "Of course" to me in the moment I worked on my code...

and now if it isn't "Of course" to others then they can read my post.

We all have different levels of knowledge @Teodor...

... and since Wappler is a tool that requires you to have less knowledge than before, my post is here to help others like me!

just a few of all the topics asking the same question.

1 Like