--- title: "Content Templates in Vue 3 Editor" description: "Offer Vue 3 users a searchable picker of grouped HTML snippets defined under templates in :init, with sanitized preview and a template-insert event." head: - - meta - name: robots content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: googlebot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: bingbot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' --- # Content Templates in the Vue 3 Editor A Vue 3 `` can offer a picker of reusable HTML snippets, for example reply texts, proposal headers, or document outlines. Define them as `EditorTemplateItem` objects under `templates` in your `:init` binding and listen for `@template-insert` to run code after a user inserts one. Snippets can contain [merge tags](./merge-tags.html) like {{client.name}}; Step 5 of the [Laravel and Inertia guide](./laravel-integration.html) replaces them with real values after insertion. --- ## Key Highlights - 📋 **Consumer-defined content**: Templates come only from `init.templates.items`, so the list matches your app. - 🔍 **Searchable picker**: Filter by label or description, or switch between tabs built from each item's `group`. - 👁️ **Sanitized preview**: See how a template renders before it lands in the document. - 🎯 **Caret-aware insert**: The snippet is placed at the saved selection and the new HTML flows into `v-model`. --- ## Configuration and Item Properties Define template items in `init.templates`: ```ts import type { EditorInit, EditorTemplateItem } from '@erag/text-editor-vue'; const templateItems: EditorTemplateItem[] = [ { id: 'message-received', label: 'Message Received', description: 'Confirm that a request was received.', group: 'Quick Replies', content: '

Hi {{client.name}},

We received your message and will get back to you shortly.

', }, { id: 'progress-update', label: 'Progress Update', description: 'Share a brief progress update with the client.', group: 'Quick Replies', content: '

Hi {{client.name}},

' + '

Just a quick note to let you know we are working on your request.

' + '

Best regards,
{{consultant.name}}

', }, { id: 'hero-with-link', label: 'Hero Header Block', description: 'A reusable introduction block with call to action link.', group: 'Hero Blocks', content: '

Welcome, {{client.name}}

' + '

Your proposal is ready for review.

' + '

Review Proposal

', }, ]; const editorConfig: EditorInit = { templates: { enabled: true, items: templateItems, }, }; ``` | Option | Type | Default | Description | | --------- | ---------------------- | ------- | ----------------------------------------------- | | `enabled` | `boolean` | `true` | Enables an object-based template configuration. | | `items` | `EditorTemplateItem[]` | `[]` | Consumer-owned templates shown by the picker. | No starter templates are bundled. The Templates menu appears only when the feature is enabled and at least one item is configured. ### Template Item Interface (`EditorTemplateItem`) | Property | Type | Required | Description | | :------------ | :----------------- | :------- | :--------------------------------------------------------------------------- | | `id` | `string \| number` | **Yes** | Stable identifier for the template item. | | `label` | `string` | **Yes** | Display title shown in the list and dialog. | | `content` | `string` | **Yes** | HTML content string inserted into the editor. | | `group` | `string` | Optional | Category name for group tab filtering (e.g. `Quick Replies`, `Hero Blocks`). | | `description` | `string` | Optional | Short summary description shown under the label. | --- ## Interactive Template Modal Dialog Enabling templates adds a dynamic top-level **Templates** menubar entry when configured items exist. If `menubar` is an explicit array, include `'templates'` at the desired position, as shown in [menubar customization](./menubar-customization.html). Opening the modal presents: 1. **Search Bar**: Instant filter by template name, description, or group. 2. **Category Tabs**: Filter templates by specified `group` names. 3. **Live Preview Frame**: Displays how the template's HTML will render once inserted. 4. **Insert Button**: Inserts the selected template at the cursor location and closes the modal. --- ## Template Events Listen to the `template-insert` event to trigger application behavior whenever a user inserts a template: ```vue ```