Merge Tags in the Vue 3 Editor
In a Vue 3 app, merge tags are set on the mergeTags key of the object you pass to :init, often built with computed so the list can change at runtime. Users insert placeholders such as client.name from an autocomplete list that opens after {{ or from a grouped sidebar in the menubar, and the component emits merge-tag-select and merge-tag-remove so your code can follow which tags a document uses.
Merge tags pair well with templates, whose content can include the same placeholders. To tag people instead, see mentions.
Merge tags are disabled by default. The trigger is fixed as {{; item values are normalized to the same double-braced form before display, insertion, and event emission.
Key Highlights
Fixed Trigger
The {{ trigger is fixed. As soon as it is typed, a filtered menu of matching tags appears at the cursor.
Grouped Slide-out Drawer
The sidebar groups tags by the group value of each item, for example Client, Proposal, and Billing.
Atomic Token Chips
Tags appear as locked inline chips. Pressing Backspace or Delete next to one removes the entire chip at once.
Safe HTML Storage
The v-model HTML keeps each tag as structured data attributes like data-erag-merge-tag-value.
Configuration and Item Interface
Define merge tag items in init.mergeTags:
import { computed } from 'vue';
import type { EditorInit, MergeTagItem } from '@erag/text-editor-vue';
const mergeTagItems = computed<MergeTagItem[]>(() => [
{ value: '{{amit}}', name: 'Consultant name' },
{ value: '{{client.name}}', name: 'Client name', group: 'Client' },
{
value: '{{client.salutation}}',
name: 'Client salutation',
group: 'Client',
},
{
value: '{{submission.date}}',
name: 'Submission date',
group: 'Proposal',
},
{
value: '{{proposal.number}}',
name: 'Proposal number',
group: 'Proposal',
},
]);
const editorConfig = computed<EditorInit>(() => ({
mergeTags: {
enabled: true,
limit: 10,
items: mergeTagItems.value,
},
}));| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enables the feature for an object configuration. |
limit | number | 10 | Maximum autocomplete results. |
items | MergeTagItem[] | [] | Consumer-provided tags displayed by the UI. |
The package does not invent merge tags. Supply at least one item for the menubar entry, sidebar, and suggestions to have content.
Merge Tag Item Interface (MergeTagItem)
| Property | Type | Required | Description |
|---|---|---|---|
value | string | Yes | Visible and stored token value, normally supplied as {{client.name}}. A bare or single-braced value is normalized to double braces. |
name | string | Optional | Friendly display name shown in autocomplete and the sidebar. The inserted token remains the normalized value. |
group | string | Optional | Group name used to categorize tags in the right slide-out drawer (e.g. Client, Proposal). |
Sidebar Panel and Menubar Integration
When mergeTags.enabled is true, a Merge tag menu option is added to the menubar. Clicking it opens a right slide-out sidebar drawer organized by category groups.
If you specify an explicit menubar array in configuration, include 'merge-tags'. The other menu names are listed in menubar customization:
const editorConfig: EditorInit = {
menubar: ['file', 'edit', 'insert', 'format', 'merge-tags'],
mergeTags: {
enabled: true,
items: mergeTagItems.value,
},
};The sidebar keeps ungrouped items in a common list and renders named groups as separate sections. Clicking an item restores the saved editor selection and inserts the tag at that caret position.
Autocomplete controls
After typing {{, suggestions are filtered against friendly names, normalized values, and group names. Starts-with matches appear before contains matches, and limit controls the maximum visible results.
ArrowDown/ArrowUpmoves through results and wraps.Home/Endjumps to the first or last result.Enter/Tabinserts the active result.Escapecloses the dropdown.- Backspace after a token or Delete before it removes the complete token and emits
merge-tag-remove.
Merge Tag Events
Listen to tag selection and removal events:
<script setup lang="ts">
import { shallowRef } from 'vue';
import {
Editor,
type MergeTagRemoveEvent,
type MergeTagSelectEvent,
} from '@erag/text-editor-vue';
const content = shallowRef('');
function handleTagSelect(event: MergeTagSelectEvent) {
console.log('Inserted merge tag:', event.item.value);
}
function handleTagRemove(event: MergeTagRemoveEvent) {
console.log('Removed merge tag:', event.item.value);
}
</script>
<template>
<Editor
v-model="content"
:init="editorConfig"
@merge-tag-select="handleTagSelect"
@merge-tag-remove="handleTagRemove"
/>
</template>merge-tag-select: Emitted with{ item, query }when a tag is inserted from autocomplete or the sidebar.merge-tag-remove: Emitted with{ item }whenBackspaceorDeleteremoves an inserted token.
HTML Output and Backend Replacement
Inserted merge tags render as atomic non-editable token chips in exported HTML:
<span
class="erag-merge-tag"
data-erag-merge-tag="true"
data-erag-merge-tag-value="{{client.name}}"
contenteditable="false"
>{{client.name}}</span
>Backend Placeholder Resolution Example (Laravel / PHP)
Before sending an email or rendering a PDF report, parse the stored HTML and replace only recognized merge-tag elements. Avoid a global string replacement because it also changes the token's data attribute and leaves stale chip markup behind.
$document = new DOMDocument();
$document->loadHTML(
'<meta charset="utf-8"><body>'.$template->body.'</body>',
LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD,
);
$replacements = [
'{{client.name}}' => $client->name,
'{{client.salutation}}' => $client->salutation,
'{{consultant.name}}' => $consultant->name,
];
$xpath = new DOMXPath($document);
foreach ($xpath->query('//span[@data-erag-merge-tag="true"]') as $node) {
$token = $node->attributes?->getNamedItem('data-erag-merge-tag-value')?->nodeValue;
if ($token !== null && array_key_exists($token, $replacements)) {
$node->parentNode?->replaceChild(
$document->createTextNode($replacements[$token]),
$node,
);
}
}Serialize the body children after replacement and pass the result through your server-side HTML sanitizer, keeping the attributes listed in security and sanitization. For an end-to-end example with a Laravel controller, see the Laravel and Inertia guide. Only replace values from an application allowlist. Do not treat a stored tag as executable code or as an arbitrary object path.