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: blazor/rich-text-editor/mail-merge.md
+77-40Lines changed: 77 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,9 @@ control: RichTextEditor
7
7
documentation: ug
8
8
---
9
9
10
-
# Mail Merge in Syncfusion Blazor RichTextEditor
10
+
# Mail Merge in Blazor Rich Text Editor
11
11
12
-
The Mail Merge feature in Syncfusion Blazor RichTextEditor enables developers to create dynamic, personalized documents by inserting placeholders (merge fields) into the editor content. These placeholders are later replaced with actual data at runtime, making it ideal for generating letters, invoices, and bulk communication templates.
13
-
14
-
## Key Outcomes:
15
-
16
-
- Render custom toolbar items for mail merge actions.
17
-
- Insert merge fields dynamically using dropdown or Mention control.
18
-
- Replace placeholders with real data using a single click.
12
+
The Mail Merge feature in Blazor Rich Text Editor enables developers to create dynamic, personalized documents by inserting placeholders (merge fields) into the editor content. These placeholders are later replaced with actual data at runtime, making it ideal for generating letters, invoices, and bulk communication templates.
19
13
20
14
## Rendering Custom Toolbar Items
21
15
@@ -30,14 +24,20 @@ Custom toolbar items are added using the [RichTextEditorCustomToolbarItems](http
@@ -46,42 +46,48 @@ Custom toolbar items are added using the [RichTextEditorCustomToolbarItems](http
46
46
{% endhighlight %}
47
47
{% endtabs %}
48
48
49
-
## Executing Merge Data Action
49
+
## Populating and Using Insert Field Dropdown
50
50
51
-
When the `Merge Data` button is clicked:
51
+
The `Insert Field` dropdown in the Rich Text Editor is designed to let users quickly insert predefined merge fields into the editor content. This dropdown is powered by the `SfDropDownButton` control, which uses its [Items](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SplitButtons.SfDropDownButton.html#Syncfusion_Blazor_SplitButtons_SfDropDownButton_Items) property to bind a collection of menu items.
52
52
53
-
1. The editor’s current content (rte.Value) is retrieved.
54
-
2. A regex-based function scans for placeholders in the format {{FieldName}}.
55
-
3. Each placeholder is replaced with its corresponding value from a dictionary.
53
+
### How the Items Property Works
56
54
57
-
```csharp
55
+
- The `Items` property accepts a list of [DropDownMenuItem](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SplitButtons.DropDownMenuItem.html) objects.
56
+
- Each item in this list represents a merge field and contains a [Text](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.SplitButtons.DropDownMenuItem.html#Syncfusion_Blazor_SplitButtons_DropDownMenuItem_Text) property, which is displayed in the dropdown.
57
+
- These text values correspond to the merge fields available for insertion.
This ensures all placeholders are dynamically replaced without manual editing.
79
87
80
-
## Populating and Using Insert Field Dropdown
81
-
82
-
The `Insert Field` dropdown is populated from a predefined list of merge fields (items). When a user selects an item:
88
+
When the user selects an item from the dropdown:
83
89
84
-
- The `InsertField()` method retrieves the corresponding field value.
90
+
- The `OnItemSelect()` method retrieves the corresponding field value.
85
91
- It constructs an HTML snippet with a non-editable span containing the placeholder.
86
92
- The snippet is inserted at the current cursor position using [ExecuteCommandAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.RichTextEditor.SfRichTextEditor.html#Syncfusion_Blazor_RichTextEditor_SfRichTextEditor_ExecuteCommandAsync_Syncfusion_Blazor_RichTextEditor_CommandName_System_String_Syncfusion_Blazor_RichTextEditor_ExecuteCommandOption_).
87
93
@@ -98,6 +104,7 @@ The `Insert Field` dropdown is populated from a predefined list of merge fields
98
104
}
99
105
}
100
106
```
107
+
101
108
## Role of Mention Control in Mail Merge
102
109
103
110
Mention control enhances usability by enabling inline field suggestions:
@@ -149,7 +156,6 @@ When the `Insert Field` dropdown opens, the editor loses its current selection b
149
156
}
150
157
```
151
158
152
-
153
159
## Handling Editor Mode Changes with OnActionComplete
154
160
155
161
The [OnActionComplete](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.RichTextEditor.RichTextEditorEvents.html#Syncfusion_Blazor_RichTextEditor_RichTextEditorEvents_OnActionComplete) event fires after specific actions in the RichTextEditor, such as switching between Source Code and Preview modes.
@@ -177,6 +183,37 @@ The [OnActionComplete](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.R
177
183
178
184
**Why is this important?** This prevents users from triggering merge operations or inserting fields while editing raw HTML, which could cause unexpected behavior.
179
185
186
+
## Executing Merge Data Action
187
+
188
+
When the `Merge Data` button is clicked:
189
+
190
+
- The editor’s current content is retrieved by using [Value](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.RichTextEditor.SfRichTextEditor.html#Syncfusion_Blazor_RichTextEditor_SfRichTextEditor_Value) property.
191
+
- A regex-based function scans for placeholders in the format {{FieldName}}.
192
+
- Each placeholder is replaced with its corresponding value from a dictionary.
0 commit comments