CKEditor4: Make Text Differ from its HTML

余生长醉 提交于 2019-12-01 16:49:45

Is a workaround fine? If you can post- and preprocess the data, the solution is simple. Preprocess the data incoming by replacing ${__VCG__VAL__FIRST_NAME} with $[FIRST_NAME] and before saving, do the opposite.

For a fancier method with more complicated replaces but has a nicer UX, I'd use widgets with code like this:

<p data-real="${__VCG__VAL__FIRST_NAME}">$[FIRST_NAME]</p>

You'd create a plugin that defines that every P with a data-real attribute as a widget. Then before saving you'd convert them into the simple P you like and when loading you'd convert the simple P back to the widget. The benefits here is that the user can't accidentally edit the text and that drag and drop is easy. The replaces should be pretty easy with jquery for example.

I don't know why you'd want them to be block level though, I'd imagine that variables such as these would be nicer inline - but that's up to your requirements.

Widget documentation at http://docs.ckeditor.com/#!/guide/dev_widgets

I agree with Nenotleps. When a user confirms the editors input, just replace $[FIRST_NAME] with <p>${__VCG__VAL__FIRST_NAME}</p> and if some data is load to the editor do it the other way round.

You can get the current editor content in html with editor.getData(), where editor is your ckeditor instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!