« All Handlers

onWidgetFormat

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:

  1. 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.

  2. 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$_LW->REGISTERED_APPS['my_app']=array(
'title'=>'My App',
'handlers'=>array('onWidgetFormatEvents'),
);

class LiveWhaleApplicationMyApp {

public function onWidgetFormatEvents($handler, $buffer) {
global $_LW;

if ($handler=='onDisplay') {

// Replace "until" with "through" in widget output for date ranges
if (!empty($buffer['until'])) {
$buffer['until'] = str_replace('until', 'through', $buffer['until'])
};

// Use a.m./p.m. in time strings
if (!empty($buffer['time'])) {
$buffer['time'] = str_replace(array('am','pm'),array('a.m','p.m'), $buffer['time']);
};
if (!empty($buffer['start_time'])) {
$buffer['start_time'] = str_replace(array('am','pm'),array('a.m','p.m'), $buffer['start_time']);
};
if (!empty($buffer['end_time'])) {
$buffer['end_time'] = str_replace(array('am','pm'),array('a.m','p.m'), $buffer['end_time']);
};

};

return $buffer;
}

}
?>