--- name: unlayer-integration description: Integrates Unlayer's email, page, popup, and document builders into web applications through React, Vue, Angular, or plain JavaScript. Use for builder component setup, props, editor access patterns, and multiple instances. For the standalone Image Editor or @unlayer/react-image-editor, use unlayer-image-editor. --- # Integrate Unlayer Editor ## Overview Unlayer provides official wrappers for React, Vue, and Angular, plus a plain JavaScript embed. All wrappers share the same underlying API — only the editor access pattern differs. This skill covers the email, page, popup, and document builders. For the standalone Image Editor or `@unlayer/react-image-editor`, use `unlayer-image-editor`. ## Which Framework? | Framework | Package | Install | Editor Access | |-----------|---------|---------|---------------| | React | `react-email-editor` | `npm i react-email-editor` | `useRef` → `ref.current?.editor` | | Vue | `vue-email-editor` | `npm i vue-email-editor` | `this.$refs.emailEditor.editor` | | Angular | `angular-email-editor` | `npm i angular-email-editor` | `@ViewChild` → `this.emailEditor.editor` | | Plain JS | CDN script tag | ` ``` **Props:** `minHeight`, `options`, `tools`, `appearance`, `locale`, `projectId`. > Docs: https://docs.unlayer.com/builder/vue-component > GitHub: https://github.com/unlayer/vue-email-editor --- ## Angular (Complete Working Example) ```bash npm install angular-email-editor --save ``` **Module (app.module.ts):** ```typescript import { EmailEditorModule } from 'angular-email-editor'; @NgModule({ imports: [EmailEditorModule] }) export class AppModule {} ``` **Component (app.component.ts):** ```typescript import { Component, ViewChild } from '@angular/core'; import { EmailEditorComponent } from 'angular-email-editor'; @Component({ selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { @ViewChild(EmailEditorComponent) private emailEditor: EmailEditorComponent; saving = false; async editorLoaded() { try { const response = await fetch('/api/templates/123'); if (response.ok) { const saved = await response.json(); this.emailEditor.editor.loadDesign(saved.design); } } catch (err) { console.log('No saved design'); } } handleSave() { this.saving = true; this.emailEditor.editor.exportHtml(async (data) => { try { await fetch('/api/templates', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ design: data.design, html: data.html }), }); } catch (err) { console.error('Save error:', err); } finally { this.saving = false; } }); } } ``` **Template (app.component.html):** ```html
``` > Docs: https://docs.unlayer.com/builder/angular-component --- ## Plain JavaScript ```html
``` > Docs: https://docs.unlayer.com/builder/installation --- ## Multiple Editor Instances Use `createEditor()` instead of `init()`: ```javascript const editor1 = unlayer.createEditor({ id: 'email-editor', displayMode: 'email' }); const editor2 = unlayer.createEditor({ id: 'web-editor', displayMode: 'web' }); editor1.loadDesign(emailDesign); editor2.loadDesign(webDesign); ``` --- ## Common Mistakes | Mistake | Fix | |---------|-----| | Container too small | Minimum **1024px wide x 700px tall**. Editor fills its container. | | Calling methods before ready | Always wait for `editor:ready` event or `onReady` callback | | Using `init()` for multiple editors | Use `unlayer.createEditor()` instead | | Missing `projectId` | Get it from Dashboard > Project > Settings | | Only saving HTML, not design JSON | Always save **both** — design JSON lets users edit later | | No loading state while saving | Disable the save button to prevent double saves | | Pinning a non-existent package version | Run `npm view version` to verify before pinning. Use `npm install --save` without a version to get the latest. | ## Troubleshooting | Error | Cause | Fix | |-------|-------|-----| | Editor shows blank white space | Container div has 0 height | Set explicit height: `min-height: 700px` | | `editor:ready` never fires | Script not loaded or wrong `id` | Check `id` matches an existing div, check network tab for embed.js | | `ref.current?.editor` is undefined | Accessed before mount | Only use inside `onReady` callback | | Design doesn't load | Malformed JSON | Validate JSON, check `schemaVersion` field | ## Resources - [Installation Guide](https://docs.unlayer.com/builder/installation) - [React Component](https://docs.unlayer.com/builder/react-component) - [Vue Component](https://docs.unlayer.com/builder/vue-component) - [Angular Component](https://docs.unlayer.com/builder/angular-component)