Search code examples
phphtmltinymcesmarty

Disable TinyMCE auto clean up


I want to use the tinymce editor to edit smarty templates. The problem is that the editor always rearrange the code. If I enter this code in to the HTML window:

<table border="0">
<tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
{if empty($test)}
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
{/if}
</tbody>
</table>

turns into this code after clicking the OK button:

<p>{if empty($test)} {/if}</p>
<table border="0">
<tbody>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

Solution

  • I've never written one but I presume that JavaScript-powered HTML editors don't work directly on HTML. Instead, they probably build a DOM tree in memory. You are not working on plain HTML but on Smarty code. That means that you'll always lose information if you handle it as HTML since it's not such thing. The example you give illustrates it pretty well: there is no way to represent that string as HTML; if you open it inside a browser, it will look broken.

    The plain fact is that visual HTML editors are designed to edit HTML. Smarty templates only resemble HTML.