Installation
This page will help you get started with Unlayer. You'll be up and running in a jiffy!
Add JavaScript Library
The first step is to add the following JavaScript library to your web app. This will load all the required assets for you to initialize the editor.
<script src="//editor.unlayer.com/embed.js"></script>
If you are using React, Angular or Vue, check our components available on npm:
Initialize Editor
The Unlayer editor needs a container HTML element on your page to be rendered inside. Let's add a blank div first.
<div id="editor-container"></div>
Recommended Size
It is recommended that the container has a minimum width of 1024px and minimum height of 700px. The editor is designed to be fluid and will take full width and height of the container.
Now, we'll initialize the editor in the blank div above by passing it's id and some other configuration options.
unlayer.init({
id: 'editor-container',
projectId: 1234,
displayMode: 'email'
})
Configuration Options
These are all the configuration options available that can be passed to the unlayer.init
method.
Attribute | Required | |
---|---|---|
id | Yes | This is the HTML div id of the container where the editor will be embedded. |
displayMode | No | This is the template display mode which can be |
projectId | No | This is the project ID from Unlayer. You can get it from the project settings page. |
locale | No | This is the locale you want to load the editor in. We have many translations available. Learn more |
appearance | No | These are the appearance options to change the look and feel of the editor. Learn more |
user | No | This is the info of the user who is using the editor. You can pass |
mergeTags | No | This is an array of objects. You can pass the merge tags to display in the editor. Learn more |
designTags | No | You can pass design tags in this object. Learn more |
specialLinks | No | You can pass special links in this object. Learn More |
tools | No | These are the options for tools and custom tools. Learn more |
blocks | No | This is an array of objects. You can pass custom blocks here. Learn more |
editor | No | These are some editor options for different functions of the editor. Learn more |
fonts | No | You can pass custom fonts here. Learn More |
safeHtml | No | Sanitizes HTML output to prevent executable JavaScript from being inserted. |
customJS | No | Custom JavaScript URL or source. Learn more |
customCSS | No | Custom CSS URL or source. Learn more |
Multiple Instances
You can create multiple instances of the editor on the same page, or if you have a single page application.
const editor = unlayer.createEditor({
id: 'editor-container',
projectId: 1234,
displayMode: 'email'
})
editor.loadDesign({})
editor.exportHtml(function(data) { })
Updated over 1 year ago