opscale-co/nova-dynamic-resources package, which provides dynamic field rendering inside Laravel Nova.
What a Template Does
Instead of filling in every notification field from scratch each time, a template pre-defines the shape of the notification content. When a notification references a template, the Nova edit form renders the fields declared by that template, allowing editors to fill in the content in a structured, validated way. Templates can specify:- Fields — the input fields shown when editing a notification (e.g., subject line, body copy, CTA label, image URL).
- Default values — pre-populated content that editors can override.
- Notification type — a template can lock in a specific
NotificationType, ensuring all notifications created from it use the correct delivery strategy.
Integration with Nova Dynamic Resources
TheNotification model uses the UsesTemplate concern from opscale-co/nova-dynamic-resources:
data field stores all values for the template-defined fields as a JSON object. The UsesTemplate concern handles loading the correct field definitions and merging them with the notification’s stored data at render time.
How Templates Define Fields for Notifications
Each template class extends the Nova Dynamic Resources base and declares afields() method, returning an array of Nova field instances. These fields are injected into the notification create/edit form in Nova automatically when a template is selected.
This means:
- Different templates can expose entirely different sets of input fields.
- Field validation rules are defined once in the template and reused across all notifications that reference it.
- Template fields are stored in the notification’s
datacolumn, keeping thenotificationstable schema stable regardless of template variations.
Defining Notification Type in a Template
A template can prescribe aNotificationType, which is then applied to any notification created from that template. This is useful when you have channel-specific or purpose-specific templates (e.g., an “Urgent Alert” template that always maps to the Alert type and its fast-escalation strategy).
Managing Templates in Nova
Create a template
Click Create Template, give it a name, and define its fields and any default notification type.
Attach to a notification
When creating or editing a notification, select the template from the Template field. The form will update to show the template’s fields.
A notification does not require a template. If no
template_id is set, the standard subject, body, summary, and action fields are used directly.