开发者

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>


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.


All text needs to be inside a html container - usually a p-tag. That is the reason why

{if empty($test)}

transforms to

<p>{if empty($test)} {/if}</p>

. You may choose to wrap this code inside a tag of your choice, but it needs to be inside an element!


Use html comments instead:

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜