Expand description
Third-party custom widget registry.
Out-of-tree crates ship new widget types via
register_widget!. Each registration carries the wire-format
name (used by crate::widget::WidgetKind::Custom and looked
up at render time) and the Tera template path the bundled
_widget.html macro should include for that name.
§Why no JS class
A widget needs no client-side class keyed by a string name that
could fail at runtime if mismatched. The plumbing
here is just a Tera template — the same one the server uses to
render the widget. Native HTML5 inputs cover most needs
(<input type="color">, <input type="date">, <input type="range">); for the rare widget that wants client-side
sprinkle (e.g. a map preview reacting to lat/lng inputs), the
template can emit a <script> tag inline or a data-* hook the
host app’s own bundle reads. No framework-imposed JS class
registry.
§Example
use rustango_cms::register_widget;
register_widget!("latlng", "widgets/latlng.html");Inside a PageTypeHandler::extension_fields impl:
Widget::new(
WidgetKind::Custom { name: "latlng".to_owned() },
"office_loc",
"Office location",
)Structs§
- Custom
Widget Registration - One registered custom widget — wire-format
namepaired with the Tera template that renders it. Submitted viaregister_widget!and collected at startup by theinventorycrate.
Functions§
- duplicate_
widget_ names - Surface duplicate registrations at boot. Returns the list of duplicate names; the empty Vec means clean. Host apps should call this once at startup and panic / log on non-empty output — silent duplicates would lead to one of two competing templates winning arbitrarily depending on link order.
- find_
custom_ widget - Look up the registered template path for a custom widget by
name. Returns
Nonewhen the name isn’t registered — callers (the_widget.htmlmacro path) treat this as an editor-visible error rather than panicking. - registered_
widgets - Iterator over every registered custom widget. Returned references
are
'static— registrations are process-global. - validate_
registry - Boot-time validation hook: checks for duplicate widget names.