The onWidgetFormat handler (and its more specific siblings, onWidgetFormatEvents, onWidgetFormatNews, onWidgetFormatProfiles, etc.) allow you to filter a widget’s variables just before they are displayed.
There are two unique aspects to onWidgetFormat you should keep in mind:
Since onWidgetFormat is executed in several contexts, it receives a $handler variable that lets you specify what context your code should affect. The most common use is “onDisplay”, as in the example below, but you may have code for the handlers “json”, “calendar”, or others.
You can use
onWidgetFormatType($handler, $buffer) (replacing Type with Events, News, Profiles, etc.) instead of
onWidgetFormat($type, $handler, $buffer) if you’re targeting just one type of widget. Always opt to use the type-specific one over the non-type-specific one when possible.