parse ckeditor content and apply tags instead of displaying them on the screen

677 views Asked by At

I have a problem parsing the content of CKEditor. I have saved the data into mongoDB but when I retrieve the content to display, it shows the tags instead of parsing them.

The content had this formatting when I saved it. This is how I want it to display when I retrieve it from the database.

But this is the content I am getting when I retrieve from the database. I want it to apply the tags but not displaying them. so I can have the same formatting as I entered.

<p>The <strong>content had thi</strong>s formatting <em>when I saved it. This is how</em> I want it to display <strong><em>when I retrieve it from the database</em></strong>.</p>

My html page is the following when I tried to display the content:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">


    <script src="https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js"></script>

</head>

<body>    
    <div id="pgContent">
        <div class="container">
            <span class="line"></span>
            <div id="msgContent" style="max-width:800px; font-size:16px;">&lt;p&gt;The &lt;strong&gt;content had thi&lt;/strong&gt;s formatting &lt;em&gt;when I saved it. This is how&lt;/em&gt; I want it to display &lt;strong&gt;&lt;em&gt;when I retrieve it from the database&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;</div></div></div>

</body>

There is not jquery/javascript added to it. I added javascript but it is transforming the div into an editor again:

         CKEDITOR.replace('msgContent',
{
    entities: false,
    basicEntities: false,
    entities_greek: false,
    entities_latin: false,
    htmlDecodeOutput:true,
}

I used the following when writing the message:'

         CKEDITOR.replace('msgEditor')

Update : The data in the database (mongoDB) is shown as follow:

<p>The <strong>content had thi</strong>s formatting <em>when I saved it. This is how</em> I want it to display <strong><em>when I retrieve it from the database</em></strong>.</p>\r\n

Thank you for now

1

There are 1 answers

3
Wizard On BEST ANSWER

According to Handlebars docs:

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

So, in your template change {{message.content}} to {{{message.content}}}