Skip to content

Implementation Examples

Here you can find some examples of the most common use cases for integrating the Templated Editor in your application.

Simple Editor Modal
function openTemplateEditor(userId) {
const metadata = {
userId: userId,
timestamp: new Date().toISOString()
};
const encodedMetadata = btoa(JSON.stringify(metadata));
const embedUrl = `https://app.templated.io/editor?embed=YOUR_CONFIG_ID&metadata=${encodedMetadata}`;
const modal = document.createElement('div');
modal.innerHTML = `
<div class="modal">
<embed src="${embedUrl}" width="100%" height="700px" />
<button onclick="this.parentElement.remove()">Close</button>
</div>
`;
document.body.appendChild(modal);
}
Basic Webhook
app.post('/webhook', (req, res) => {
const { event, template, metadata } = req.body;
if (event === 'save') {
console.log(`Template ${template.id} saved by user ${metadata.userId}`);
}
res.status(200).json({ received: true });
});

Launch Editor with Template and Custom Layer Data

Section titled “Launch Editor with Template and Custom Layer Data”

Pre-populate template layers with custom data when the editor loads.

Custom Layer Data
function openEditorWithCustomData(templateId, userData) {
const layerData = {
"user-name": {
text: userData.name,
color: "#333333",
font_size: "24px"
},
"user-company": {
text: userData.company,
color: "#666666",
font_size: "18px"
},
"profile-image": {
image_url: userData.profileImage
},
"background-shape": {
fill: userData.brandColor || "#0066CC"
}
};
const encodedLayers = btoa(JSON.stringify(layerData));
const embedUrl = `https://app.templated.io/editor/${templateId}?embed=YOUR_CONFIG_ID&layers=${encodedLayers}`;
window.open(embedUrl, '_blank');
}
// Usage example
const userData = {
id: 'user123',
name: 'John Smith',
company: 'Acme Corp',
profileImage: 'https://example.com/profile.jpg',
brandColor: '#FF6B35'
};
openEditorWithCustomData('template_abc123', userData);

Edit an existing render by loading it into the editor.

Edit Existing Render
function editExistingRender(renderId, userId) {
const metadata = {
userId: userId,
renderId: renderId,
mode: 'edit_render'
};
const encodedMetadata = btoa(JSON.stringify(metadata));
const embedUrl = `https://app.templated.io/editor?embed=YOUR_CONFIG_ID&metadata=${encodedMetadata}`;
// Open in modal
const modal = document.createElement('div');
modal.className = 'render-editor-modal';
modal.innerHTML = `
<div class="modal-backdrop">
<div class="modal-content">
<div class="modal-header">
<h3>Edit Design</h3>
<button class="close-btn" onclick="this.closest('.render-editor-modal').remove()">×</button>
</div>
<iframe src="${embedUrl}" width="100%" height="800px" frameborder="0"></iframe>
</div>
</div>
`;
document.body.appendChild(modal);
}
// Alternative: Edit render with custom callback
function editRenderWithCallback(renderId, onSave) {
const metadata = {
renderId: renderId,
callback: 'custom',
onSave: onSave.toString() // Pass callback function
};
const encodedMetadata = btoa(JSON.stringify(metadata));
const embedUrl = `https://app.templated.io/editor?embed=YOUR_CONFIG_ID&metadata=${encodedMetadata}`;
return embedUrl;
}

Create a clone of a template that doesn’t appear in your dashboard.

Template Clone Mode
function cloneTemplate(templateId, userId, customizations = {}) {
const metadata = {
userId: userId,
mode: 'clone',
templateId: templateId,
customizations: customizations
};
const encodedMetadata = btoa(JSON.stringify(metadata));
const embedUrl = `https://app.templated.io/editor/${templateId}?embed=YOUR_CONFIG_ID&metadata=${encodedMetadata}`;
// Open in new tab
const newWindow = window.open(embedUrl, '_blank');
// Optional: Listen for completion
const checkClosed = setInterval(() => {
if (newWindow.closed) {
clearInterval(checkClosed);
console.log('Template clone editor closed');
// Handle post-clone actions
}
}, 1000);
}
// Example with product customization
function customizeProduct(productId, templateId) {
const customizations = {
productId: productId,
allowedElements: ['text', 'image'], // Restrict editing
hiddenLayers: ['background', 'logo'], // Lock certain layers
requiredFields: ['customer_name', 'order_number']
};
cloneTemplate(templateId, 'customer_123', customizations);
}
// Usage examples
const templateId = 'template_xyz789';
const userId = 'user_456';
// Basic clone
cloneTemplate(templateId, userId);
// Clone with restrictions
cloneTemplate(templateId, userId, {
allowedElements: ['text'],
maxTemplates: 5
});

Implementation Tips

Start Simple: Begin with a basic modal implementation and gradually add features.

Test Thoroughly: Always test your webhook endpoints and metadata encoding.

Security First: Validate all metadata on your server before processing.

User Experience: Provide clear feedback and loading states for users.