You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ej2-javascript/rich-text-editor/smart-editing/mail-merge.md
+70-70Lines changed: 70 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,25 +10,25 @@ domainurl: ##DomainURL##
10
10
---
11
11
12
12
# Mail merge in ##Platform_Name## Rich Text Editor Control
13
-
13
+
14
14
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
+
16
16
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
+
18
18
## Adding custom toolbar items for inserting merge fields
19
-
19
+
20
20
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
+
22
22
-**Insert Field:** Opens a dropdown list of merge fields for inserting placeholders like `{{FirstName}}` into the editor.
23
23
-**Merge Data:** Replaces all placeholders in the editor with actual values from a predefined data source.
24
-
24
+
25
25
{% if page.publishingplatform == "typescript" %}
26
-
26
+
27
27
{% tabs %}
28
28
{% highlight ts tabtitle="app.ts" %}
29
-
29
+
30
30
{% raw %}
31
-
31
+
32
32
const mailMergeEditor: RichTextEditor = new RichTextEditor({
33
33
toolbarSettings: {
34
34
items: [
@@ -41,19 +41,19 @@ const mailMergeEditor: RichTextEditor = new RichTextEditor({
var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
58
58
toolbarSettings: {
59
59
items: [
@@ -66,24 +66,24 @@ var mailMergeEditor = new ej.richtexteditor.RichTextEditor({
66
66
},
67
67
});
68
68
mailMergeEditor.appendTo('#mailMergeEditor');
69
-
69
+
70
70
{% endraw %}
71
-
71
+
72
72
{% endhighlight %}
73
73
{% endtabs %}
74
74
{% endif %}
75
-
75
+
76
76
## Using DropDownButton for selecting placeholders
77
-
77
+
78
78
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
+
80
80
{% if page.publishingplatform == "typescript" %}
81
-
81
+
82
82
{% tabs %}
83
83
{% highlight ts tabtitle="app.ts" %}
84
-
84
+
85
85
{% raw %}
86
-
86
+
87
87
let insertField: DropDownButton = new DropDownButton({
88
88
items: [
89
89
{ text: 'First Name' },
@@ -100,7 +100,7 @@ let insertField: DropDownButton = new DropDownButton({
100
100
select: onItemSelect,
101
101
});
102
102
insertField.appendTo('#insertField');
103
-
103
+
104
104
function onItemSelect(args: MenuEventArgs): void {
105
105
const value = textToValueMap[args.item.text];
106
106
mailMergeEditor.executeCommand(
@@ -109,19 +109,19 @@ function onItemSelect(args: MenuEventArgs): void {
var insertField = new ej.splitbuttons.DropDownButton({
126
126
items: [
127
127
{ text: 'First Name' },
@@ -137,7 +137,7 @@ var insertField = new ej.splitbuttons.DropDownButton({
137
137
select: onItemSelect,
138
138
});
139
139
insertField.appendTo('#insertField');
140
-
140
+
141
141
function onItemSelect(args) {
142
142
if (args.item.text != null) {
143
143
var value = textToValueMap[args.item.text];
@@ -152,24 +152,24 @@ function onItemSelect(args) {
152
152
);
153
153
}
154
154
}
155
-
155
+
156
156
{% endraw %}
157
-
157
+
158
158
{% endhighlight %}
159
159
{% endtabs %}
160
160
{% endif %}
161
-
161
+
162
162
## Populating merge fields using Mention
163
-
163
+
164
164
The **Mention** control provides an alternative way to insert placeholders by typing the <code>{{</code> character inside the editor. A popup list of merge fields appears, allowing quick selection without using the toolbar.
165
-
165
+
166
166
{% if page.publishingplatform == "typescript" %}
167
-
167
+
168
168
{% tabs %}
169
169
{% highlight ts tabtitle="app.ts" %}
170
-
170
+
171
171
{% raw %}
172
-
172
+
173
173
const mentionObj: Mention = new Mention({
174
174
dataSource: mergeData,
175
175
target: '#mailMergeEditor',
@@ -181,19 +181,19 @@ const mentionObj: Mention = new Mention({
@@ -205,48 +205,48 @@ var mergeObj = new ej.dropdowns.Mention({
205
205
allowSpaces: true,
206
206
});
207
207
mergeObj.appendTo('#mentionField');
208
-
208
+
209
209
{% endraw %}
210
-
210
+
211
211
{% endhighlight %}
212
212
{% endtabs %}
213
213
{% endif %}
214
-
214
+
215
215
## Replacing placeholders with actual data dynamically
216
-
216
+
217
217
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.
0 commit comments