1

I have a requirement where the authors want a button in RTE which can wrap selected text with a predefined html structure. E.g.

This is the Selected Text

Now we want a button/tool in Sitecore Rich Text Editor, on clicking on which, the select text gets wrapped as the following html markup.

<sometag class="some-class">
<p class="another-class">
This is the Selected Text
</p>
</sometag>

I have tried adding an option in the formatblock section of Sitecore but apparently it only supports single tag since it is paragraph styling.

I have also tried the insert snippet functionality but insert snippet inserts the whole structure to RTE. It does not wrap the pre-selected text in the snippet.

Please suggest if we can achieve this by any out of the box RTE functionality or if this is feasible.

2 Answers 2

1

It sounds like you need some kind of drop down button that will have the preformatted HTML you want to insert with your selected text? is that correct? You will need to add a custom button to the RTE.

I wrote a blog here on how to do that. However in your case you will need to get the selected text and insert. I would do a token for that and do a replace see code below.

Telerik.Web.UI.Editor.CommandList["InsertToken"] = function (commandName, editor, args) {
var val = args.get_value();
var seltext = args.getSelection.get_value();
editor.pasteHtml(val.replace("{seltextinsert}",seltext));
args.set_cancel(true);};

Let me know if you have any more questions.

-1

You can try below two steps -

  1. Use the anchor tag for the button

    enter image description here

  2. Use some styles to display this anchor tag as button

enter image description here

Hope these steps helps you!

Also, you can wrap all text in the anchor tag.

1
  • Maybe I am not clear what I wish to achieve. I will update the question. The buttons I am referring to here are the buttons/tools provided by sitecore in rich text editor. Now, I want to add a new button/tool on Rich Text editor which, on clicking, will wrap the selected text in markup mentioned in the question.
    – Shaurya
    Commented Jan 3, 2019 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.