JavaScript · Advanced · Ticket 6Ticket #42 · from Kwame Mensah, Designer
  1. Example
  2. Warm-up 1
  3. Warm-up 2
  4. Ticket
Brief
NEW TICKET#42 · Email templates

Email templates with fallbacks and escaping

Kwame Mensah · Designer
Opened today

“Studios write their own reminder emails with placeholders: {{ name }}, or {{ name | there }} with a fallback after the bar. Spaces inside the braces are allowed. A value that is missing, null or an empty string uses the fallback, or nothing if there isn't one. A real value is always used, 0 included: "You owe 0" is correct. Values come from client records, so escape them for HTML (escapeHtml is written below); the fallback is the studio's own text and isn't escaped. The pattern is written. Can you finish fillTemplate?”

YOUR PLAN
  1. 1Watch an example2 min
  2. 2Warm-up 11 min
  3. 3Warm-up 21 min
  4. 4Fix the ticket31 min
BY THE END YOU CAN
  • Replace matches with a function
  • Tell a missing value apart from a falsy one
  • Escape untrusted text before it goes into HTML
About 35 minutes
Four short steps. Nothing is timed, and you can leave any time.