Skip to content

Commit cfda04d

Browse files
RTE Team conflicts resolved.
1 parent 7c0e2bf commit cfda04d

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

ej2-javascript/rich-text-editor/smart-editing/mail-merge.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ domainurl: ##DomainURL##
1010
---
1111

1212
# Mail merge in ##Platform_Name## Rich Text Editor Control
13-
13+
1414
The Rich Text Editor can be customized to implement **Mail Merge** functionality by inserting placeholders into the editor using custom toolbar items. These placeholders are later replaced with actual data to generate personalized content such as letters, invoices, and reports.
15-
15+
1616
This feature simplifies the creation of dynamic documents by allowing users to insert merge fields that are automatically populated with real data during content generation.
17-
17+
1818
## Adding custom toolbar items for inserting merge fields
19-
19+
2020
To enable mail merge functionality, the Rich Text Editor toolbar is extended with two custom buttons: `Insert Field` and `Merge Data`. These buttons are added using the `template` property in [toolbarSettings.items](https://ej2.syncfusion.com/documentation/api/rich-text-editor/toolbarsettings#items), which points to custom HTML elements (#insertField and #merge_data).
21-
21+
2222
- **Insert Field:** Opens a dropdown list of merge fields for inserting placeholders like `{{FirstName}}` into the editor.
2323
- **Merge Data:** Replaces all placeholders in the editor with actual values from a predefined data source.
24-
24+
2525
{% if page.publishingplatform == "typescript" %}
26-
26+
2727
{% tabs %}
2828
{% highlight ts tabtitle="app.ts" %}
29-
29+
3030
{% raw %}
31-
31+
3232
const mailMergeEditor: RichTextEditor = new RichTextEditor({
3333
toolbarSettings: {
3434
items: [
@@ -41,19 +41,19 @@ const mailMergeEditor: RichTextEditor = new RichTextEditor({
4141
},
4242
});
4343
mailMergeEditor.appendTo('#mailMergeEditor');
44-
44+
4545
{% endraw %}
46-
46+
4747
{% endhighlight %}
4848
{% endtabs %}
49-
49+
5050
{% elsif page.publishingplatform == "javascript" %}
51-
51+
5252
{% tabs %}
5353
{% highlight js tabtitle="index.js" %}
54-
54+
5555
{% raw %}
56-
56+
5757
var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
5858
toolbarSettings: {
5959
items: [
@@ -66,24 +66,24 @@ var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
6666
},
6767
});
6868
mailMergeEditor.appendTo('#mailMergeEditor');
69-
69+
7070
{% endraw %}
71-
71+
7272
{% endhighlight %}
7373
{% endtabs %}
7474
{% endif %}
75-
75+
7676
## Using DropDownButton for selecting placeholders
77-
77+
7878
The **DropDownButton** component displays a list of merge fields such as First Name, Last Name, and Company Name. When a user selects an item, the corresponding placeholder (e.g., {{FirstName}}) is inserted at the current cursor position using the `insertHTML` command.
79-
79+
8080
{% if page.publishingplatform == "typescript" %}
81-
81+
8282
{% tabs %}
8383
{% highlight ts tabtitle="app.ts" %}
84-
84+
8585
{% raw %}
86-
86+
8787
let insertField: DropDownButton = new DropDownButton({
8888
items: [
8989
{ text: 'First Name' },
@@ -100,7 +100,7 @@ let insertField: DropDownButton = new DropDownButton({
100100
select: onItemSelect,
101101
});
102102
insertField.appendTo('#insertField');
103-
103+
104104
function onItemSelect(args: MenuEventArgs): void {
105105
const value = textToValueMap[args.item.text];
106106
mailMergeEditor.executeCommand(
@@ -109,19 +109,19 @@ function onItemSelect(args: MenuEventArgs): void {
109109
{ undo: true }
110110
);
111111
}
112-
112+
113113
{% endraw %}
114-
114+
115115
{% endhighlight %}
116116
{% endtabs %}
117-
117+
118118
{% elsif page.publishingplatform == "javascript" %}
119-
119+
120120
{% tabs %}
121121
{% highlight js tabtitle="index.js" %}
122-
122+
123123
{% raw %}
124-
124+
125125
var insertField = new ej.splitbuttons.DropDownButton({
126126
items: [
127127
{ text: 'First Name' },
@@ -137,7 +137,7 @@ var insertField = new ej.splitbuttons.DropDownButton({
137137
select: onItemSelect,
138138
});
139139
insertField.appendTo('#insertField');
140-
140+
141141
function onItemSelect(args) {
142142
if (args.item.text != null) {
143143
var value = textToValueMap[args.item.text];
@@ -152,24 +152,24 @@ function onItemSelect(args) {
152152
);
153153
}
154154
}
155-
155+
156156
{% endraw %}
157-
157+
158158
{% endhighlight %}
159159
{% endtabs %}
160160
{% endif %}
161-
161+
162162
## Populating merge fields using Mention
163-
163+
164164
The **Mention** control provides an alternative way to insert placeholders by typing the <code>&#123;&#123;</code> character inside the editor. A popup list of merge fields appears, allowing quick selection without using the toolbar.
165-
165+
166166
{% if page.publishingplatform == "typescript" %}
167-
167+
168168
{% tabs %}
169169
{% highlight ts tabtitle="app.ts" %}
170-
170+
171171
{% raw %}
172-
172+
173173
const mentionObj: Mention = new Mention({
174174
dataSource: mergeData,
175175
target: '#mailMergeEditor',
@@ -181,19 +181,19 @@ const mentionObj: Mention = new Mention({
181181
displayTemplate: '<span> {{${value}}} </span>',
182182
});
183183
mentionObj.appendTo('#mentionField');
184-
184+
185185
{% endraw %}
186-
186+
187187
{% endhighlight %}
188188
{% endtabs %}
189-
189+
190190
{% elsif page.publishingplatform == "javascript" %}
191-
191+
192192
{% tabs %}
193193
{% highlight js tabtitle="index.js" %}
194-
194+
195195
{% raw %}
196-
196+
197197
var mergeObj = new ej.dropdowns.Mention({
198198
dataSource: mergeData,
199199
fields: { text: 'Name', value: 'Field' },
@@ -205,48 +205,48 @@ var mergeObj = new ej.dropdowns.Mention({
205205
allowSpaces: true,
206206
});
207207
mergeObj.appendTo('#mentionField');
208-
208+
209209
{% endraw %}
210-
210+
211211
{% endhighlight %}
212212
{% endtabs %}
213213
{% endif %}
214-
214+
215215
## Replacing placeholders with actual data dynamically
216-
216+
217217
When the **Merge Data** button is clicked, the editor content is processed to replace all placeholders with actual values from the `placeholderData` object. This is done using a regular expression in the `replacePlaceholders()` function.
218-
218+
219219
{% if page.publishingplatform == "typescript" %}
220-
220+
221221
{% tabs %}
222222
{% highlight ts tabtitle="app.ts" %}
223-
223+
224224
{% raw %}
225-
225+
226226
document.getElementById('merge_data')?.addEventListener('click', onClickHandler);
227-
227+
228228
function onClickHandler(): void {
229229
let editorContent = mailMergeEditor.value;
230230
let mergedContent = replacePlaceholders(editorContent, placeholderData);
231231
mailMergeEditor.value = mergedContent;
232232
}
233-
233+
234234
function replacePlaceholders(template: string, data: { [key: string]: string }): string {
235235
return template.replace(/{{\s*(\w+)\s*}}/g, (match, key) => data[key.trim()] || match);
236236
}
237-
237+
238238
{% endraw %}
239-
239+
240240
{% endhighlight %}
241241
{% endtabs %}
242-
242+
243243
{% elsif page.publishingplatform == "javascript" %}
244-
244+
245245
{% tabs %}
246246
{% highlight js tabtitle="index.js" %}
247-
247+
248248
{% raw %}
249-
249+
250250
var mergeField = document.getElementById('merge_data');
251251
if (mergeField) {
252252
mergeField.addEventListener('click', onClickHandler);
@@ -264,22 +264,22 @@ function onClickHandler() {
264264
console.log('MailMergeEditor is not initialized.');
265265
}
266266
}
267-
267+
268268
function replacePlaceholders(template, data) {
269269
return template.replace(/{{\s*(\w+)\s*}}/g, function (match, key) {
270270
var value = data[key.trim()];
271271
return value !== undefined ? value : match;
272272
});
273273
}
274-
274+
275275
{% endraw %}
276-
276+
277277
{% endhighlight %}
278278
{% endtabs %}
279279
{% endif %}
280-
280+
281281
{% if page.publishingplatform == "typescript" %}
282-
282+
283283
{% tabs %}
284284
{% highlight ts tabtitle="index.ts" %}
285285
{% include code-snippet/rich-text-editor/mail-merge/index.ts %}
@@ -288,11 +288,11 @@ function replacePlaceholders(template, data) {
288288
{% include code-snippet/rich-text-editor/mail-merge/index.html %}
289289
{% endhighlight %}
290290
{% endtabs %}
291-
291+
292292
{% previewsample "page.domainurl/code-snippet/rich-text-editor/mail-merge-cs1" %}
293-
293+
294294
{% elsif page.publishingplatform == "javascript" %}
295-
295+
296296
{% tabs %}
297297
{% highlight js tabtitle="index.js" %}
298298
{% include code-snippet/rich-text-editor/mail-merge/index.js %}
@@ -301,6 +301,6 @@ function replacePlaceholders(template, data) {
301301
{% include code-snippet/rich-text-editor/mail-merge/index.html %}
302302
{% endhighlight %}
303303
{% endtabs %}
304-
304+
305305
{% previewsample "page.domainurl/code-snippet/rich-text-editor/mail-merge-cs1" %}
306306
{% endif %}

0 commit comments

Comments
 (0)