RenderHtmlCommand
Overview
The RenderHtmlCommand renders HTML content from templates with dynamic data binding. Use this for generating HTML emails, web page previews, and reports that will be displayed in browsers.
Syntax
var result = doCmd('RenderHtmlCommand', {
Data: {
template: '<h1>Hello {{name}}</h1>',
data: { name: 'John Doe' }
}
});
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
Data.template | string | Yes | HTML template with placeholders |
Data.data | object | Yes | Data to populate template |
Data.templateId | string | No | Pre-registered template ID |
Return Value
{
"status": 200,
"message": "HTML rendered successfully",
"data": {
"html": "<h1>Hello John Doe</h1>",
"size": 1024
}
}
Examples
Example 1: Render Email Template
var htmlContent = doCmd('RenderHtmlCommand', {
Data: {
template: `
<div style="font-family: Arial;">
<h2>Welcome {{customerName}}</h2>
<p>Your account {{accountNumber}} has been created.</p>
</div>
`,
data: {
customerName: context.customerName,
accountNumber: context.accountNumber
}
}
});
// Send as HTML email
doCmd('SendEmailCommand', {
Data: {
to: context.email,
subject: 'Welcome to BankLingo',
body: htmlContent.data.html,
isHtml: true
}
});
Example 2: Generate Report Preview
var reportHtml = doCmd('RenderHtmlCommand', {
Data: {
templateId: 'monthly-report-template',
data: {
month: context.month,
totalTransactions: context.totalTransactions,
totalAmount: $.format.currency(context.totalAmount),
transactions: context.transactions
}
}
});
context.reportPreview = reportHtml.data.html;
Related Commands
- GenerateDocumentCommand - Generate full documents
- GeneratePDFCommand - Convert HTML to PDF
- SendEmailCommand - Send HTML emails
Best Practices
✅ Do's
- Use template variables for dynamic content
- Sanitize user input to prevent XSS
- Test HTML across different browsers/email clients
- Use inline CSS for email templates
❌ Don'ts
- Don't include JavaScript in email templates
- Don't forget to escape special characters
- Don't use complex CSS for emails
Version History
- v1.0 - Initial release
- v1.1 - Added template caching
- v1.2 - Improved variable binding