Skip to content
Viames Marino edited this page Feb 22, 2026 · 1 revision

Pair framework: Widget

Pair\Html\Widget renders reusable PHP widget snippets from the application widget folder.

Default widget folder:

  • APPLICATION_PATH/widgets/

Each widget is a .php file (for example widgets/stats.php).

Usage

use Pair\Html\Widget;

$widget = new Widget('stats');
$html = $widget->render();

Main methods

__construct(string $name)

Sets widget name (file without extension).

render(): string

Loads APPLICATION_PATH/widgets/<name>.php and returns rendered HTML.

If file is missing, throws PairException with ErrorCodes::WIDGET_NOT_FOUND.

availableWidgets(): array

Returns list of available widget names by scanning widget folder.

$list = Widget::availableWidgets();

Notes

  • Widget rendering is output-buffer based (ob_start + require).
  • Widget file has access to currently available PHP scope at render time.

See also: View, Application, Classes-folder.

Clone this wiki locally