What This Adds In Cloud Code
- Server-side string template rendering with JS expressions.
- Useful for dynamic email/text generation.
- Works with built-in
ejs/filtersandejs/utilshelpers.
Quick Start
js
const ejs = require('ejs');
const output = ejs.render('Hello <%= name %>!', { name: 'Alice' });API
Common exported functions include render, compile, parse, renderFile, and cache helpers.
Practical Example
js
const ejs = require('ejs');
const Mail = require('mail');
const html = ejs.render('<h1>Order <%= no %></h1><p>Total: <%= total %></p>', {
no: request.params.order_no,
total: request.params.total
});
Mail.send({ to: request.params.email, subject: 'Order confirmation', html, text: `Order ${request.params.order_no}` });Failure Modes & Gotchas
- Template syntax errors throw render errors.
- Keep templates small; large templates are harder to debug in Cloud Code.