Skip to main content

EJS

Project types
webemail
Plan
Startup plan

This plugin enables importing and exporting your Data Sources records using the EJS template engine.

EJS plugin

Install the Studio SDK plugins package:

npm i @grapesjs/studio-sdk-plugins

The example below demonstrates how the editor can detect and extract EJS expressions from the content, and how it preserves them when exporting.

import StudioEditor from '@grapesjs/studio-sdk/react';
import '@grapesjs/studio-sdk/style';
import { dataSourceEjs } from '@grapesjs/studio-sdk-plugins';
// ...
<StudioEditor
options={{
// ...
plugins: [
dataSourceEjs
],
dataSources: {
globalData: {
user: { firstName: 'Alice', isCustomer: true },
products: [
{ name: 'Laptop Pro X15', price: 1200.0 },
{ name: 'Wireless Mouse M2', price: 25.99 }
]
},
},
layout: {
default: {
type: 'row',
style: { height: '100%' },
children: [
{ type: 'sidebarLeft' },
{
type: 'canvasSidebarTop',
sidebarTop: {
rightContainer: {
buttons: ({ items }) => [{
...items.find(item => item.id === 'showCode'),
variant: 'outline',
label: 'Show code'
}],
},
},
},
{ type: 'sidebarRight' },
],
},
},
project: {
default: {
pages: [
{
name: 'Demo',
component: `
<h1>Variable</h1>
<div>Hello <%= globalData.user.data.firstName %></div>

<h1>Condition</h1>
<div>
Hey, <% if (globalData.user.data.isCustomer) { %>
welcome back <%= globalData.user.data.firstName %>!
<% } else { %>
please register to see more!
<% } %>
</div>

<h1>Collection</h1>

<% globalData.products.data.forEach(product => { %>
<div>
<b>Product Name</b>: <%= product.name %> - <b>Price</b>: <%= product.price %>
</div>
<% }) %>
`,
}
]
},

},

}}
/>

Plugin options

PropertyTypeDescription
licenseKey
string

The license key for the plugin. This is optional, only required if the plugin is used outside of Studio SDK.

Example
"your-license-key"