Prompt

How do I support templates and variables in notification messages?

Technology / API Platforms1 observationLast seen Oct 14, 2026

Latest observation

Oct 14, 2026OpenAI APIWeb search: off

A good way to support templates and variables in notification messages is to separate:

  1. the message definition
  2. the data used to fill it in at send time

1) Use a template format

Store message text with placeholders, for example:

  • "Hello {{name}}, your order {{orderId}} has shipped."
  • "Hi {name}, your balance is {balance}."

Common choices:

  • Mustache / Handlebars-style: {{name}}
  • Python-style: {name}
  • Liquid: {{ customer.name }}

Pick one and use it consistently.

2) Pass variables when sending

When sending a notification, provide a variables object/map:

{
  "template": "Hello {{name}}, your order {{orderId}} has shipped.",
  "variables": {
    "name": "Ada",
    "orderId": "12345"
  }
}

Rendered output:

Hello Ada, your order 12345 has shipped.

3) Render server-side

Usually best to render the template on the backend before dispatching the notification. Benefits:

  • consistent output
  • easier validation
  • safer than letting clients render arbitrary templates
  • simpler auditing/logging

4) Support defaults and missing values

Decide what happens if a variable is missing:

  • fail the send
  • leave placeholder unchanged
  • substitute a default value

Example:

  • {{name | default:"there"}}

5) Keep templates editable but controlled

If non-developers will edit notification text:

  • store templates in a database or CMS
  • expose a template editor with preview
  • restrict allowed variables per template

Example metadata:

{
  "id": "order_shipped",
  "body": "Hello {{name}}, your order {{orderId}} has shipped.",
  "allowedVariables": ["name", "orderId"]
}

6) Validate variables

Before rendering:

  • ensure required variables are present
  • ensure types are correct
  • sanitize any user-provided content if needed

7) Preview before sending

A preview endpoint helps:

{
  "templateId": "order_shipped",
  "variables": {
    "name": "Ada",
    "orderId": "12345"
  }
}

Return the rendered message so users can confirm it.

8) Example implementation idea

Template

Hi {{firstName}}, your verification code is {{code}}.

Send data

{
  "firstName": "Maya",
  "code": "839201"
}

Rendered

Hi Maya, your verification code is 839201.

9) If you need advanced logic

If you need conditionals, loops, or localization, choose a richer templating engine:

  • Handlebars
  • Liquid
  • Jinja2 (Python)
  • EJS (JavaScript)

Example conditional:

Hello {{name}}{{#if premium}}, thanks for being a premium member{{/if}}.

If you want, I can also show:

  • a database schema for templated notifications
  • a Node.js / Python / Java example
  • or a recommended API design for sending templated messages

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.