AshDispatch.Event.Interpolation (AshDispatch v0.5.0)
View SourceHandles variable interpolation in DSL content strings.
Supports {{variable}} syntax for interpolating values from:
- Context data (ctx.data.variable)
- Template assigns from prepare_template_assigns/2
Examples
# In DSL:
content do
subject "Order #{{order_number}} created"
notification_message "Your order for {{total_items}} items is ready"
end
# In event module:
def prepare_template_assigns(context, channel) do
%{
order_number: format_order_id(context.data.order),
total_items: length(context.data.order.items)
}
endInterpolation Rules
- Variables are looked up in template assigns first
- Fallback to context.data with same key
- Missing variables render as empty string (no errors)
- Nested access is supported with dot notation: {{project.name}}
Summary
Functions
Interpolates {{variable}} placeholders in a string.
Validates interpolation string for valid variable names.
Functions
@spec interpolate( String.t() | nil, AshDispatch.Context.t(), AshDispatch.Channel.t(), module() ) :: String.t()
Interpolates {{variable}} placeholders in a string.
Examples
iex> context = %Context{data: %{user: %{name: "John"}}}
iex> Interpolation.interpolate("Hello {{user_name}}", context, channel, event_module)
"Hello John"
iex> Interpolation.interpolate("No variables here", context, channel, event_module)
"No variables here"
Validates interpolation string for valid variable names.
Returns {:ok, variables} or {:error, reason}.
Examples
iex> Interpolation.validate("Order #{{order_number}}")
{:ok, ["order_number"]}
iex> Interpolation.validate("Invalid {{123invalid}}")
{:error, "Invalid variable name: 123invalid"}