Skip to content

Commit cfe5702

Browse files
authored
DOC-3388: Add getContent and setContent examples to save-content partial (#4052)
Add programmatic get/set content section with runnable examples using editor.getContent(), getContent({ format: 'text' }), and editor.setContent() to address Context7 benchmark Q3 (12/100).
1 parent 02966c5 commit cfe5702

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

modules/ROOT/partials/install/save-content.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,33 @@ To retrieve content from the editor, either process the content with a form hand
44

55
If you use a form handler, once the `+<form>+` is submitted, {productname} {productmajorversion} will `+POST+` the content in the same way as a normal HTML `+<textarea>+`, including the HTML elements and inline CSS of the editor content. The host's form handler can process the submitted content in the same way as content from a regular `+<textarea>+`.
66

7+
=== Get and set content programmatically
8+
9+
Use the xref:apis/tinymce.editor.adoc#getContent[`+getContent+`] and xref:apis/tinymce.editor.adoc#setContent[`+setContent+`] APIs to read and write editor content from JavaScript.
10+
11+
==== Example: retrieve editor content as HTML
12+
13+
[source,js]
14+
----
15+
const editor = tinymce.activeEditor;
16+
const html = editor.getContent();
17+
console.log(html);
18+
----
19+
20+
To retrieve the content as plain text instead of HTML:
21+
22+
[source,js]
23+
----
24+
const editor = tinymce.activeEditor;
25+
const text = editor.getContent({ format: 'text' });
26+
console.log(text);
27+
----
28+
29+
==== Example: set editor content
30+
31+
[source,js]
32+
----
33+
const editor = tinymce.activeEditor;
34+
editor.setContent('<p>New content</p>');
35+
----
36+

0 commit comments

Comments
 (0)