roy-willemse
roy-willemse

Reputation: 324

Why is TinyMCE not converting my html to their wysiwyg format?

I'm using codeigniter and have an edit page, on this page I have an TinyMCE editor. This is how I load the javascript files:

<script src='<?php echo site_url('js/tinymce/tinymce.min.js'); ?>'></script>

<script>
tinymce.init({
selector: '.tinymce'
});
</script>

This works great when adding code, and it shows up as < p > test < / p > (without spaces).

When I edit a page however, the p-tags or other tags aren't converted to the wysiwyg, they just show up as p-tags (see picture below).

p-tags showing up in the wysiwyg editor

screenshot of the source view

this is how I'm getting the data in the textarea:

<?php echo form_textarea('body', set_value('body', $page->body), 'class="form-control tinymce" placeholder="Inhoud"'); ?>

the set_value just puts the actual content inside the value of the input.

Upvotes: 1

Views: 1876

Answers (3)

Nabeel Ahmad
Nabeel Ahmad

Reputation: 1

if you use {{ $post->body }} then same database output display in html

This is working -> {!! $post->body !!}

Upvotes: 0

Pascut
Pascut

Reputation: 3434

If you're using Codeiginter 3, the "set_value()" function accepts a third parameter, html escape. Details here: http://www.codeigniter.com/userguide3/helpers/form_helper.html?highlight=set_value#set_value

So you should use:

<?php echo form_textarea('body', set_value('body', $page->body, false), 'class="form-control tinymce" placeholder="Inhoud"'); ?>

I'm using the following tinymce javascript setting also: format: 'raw'

I had the same problem and this solution works.

Next time you should also search on the codeigniter forum - https://forum.codeigniter.com/thread-1035.html

Upvotes: 1

Lahar Shah
Lahar Shah

Reputation: 7644

When You write any thing in editor it's already wrapped with tags. When you want to write html in editor,

If that sourc code is disable you can make it enable using following code snippet. (More)

tinymce.init({
  selector: "textarea",  // change this value according to your HTML
  plugins: "code",
  toolbar: "code",
  menubar: "tools"
});

There is one option at Tools > Source Code > Write your HTML code there.

enter image description here

Upvotes: 0

Related Questions