Search by

nijhof / html-builder

robnijhof

Typed HTML builder for PHP.

Package info

gitlab.com/nijhof/html-builder

Issues

pkg:composer/nijhof/html-builder

Statistics

Installs: 790

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.3 2026-10-06 12:29 UTC

This package is not auto-updated.

Last update: 2026-11-03 11:00:56 UTC


README

Typed HTML builder for PHP.

HTML Builder provides small value objects and element classes for constructing escaped HTML in PHP code. It focuses on explicit element types, typed attributes, and safe text rendering.

Requirements

  • PHP 8.3 or higher

Installation

composer require nijhof/html-builder

Example

<?php

declare(strict_types=1);

use Nijhof\Html\Elements\Div;

echo Div::of(Text::of('<content>'))->render();

Output:

<div>&lt;content&gt;</div>

Search page

Build a read-only search page with typed routes, field names and values. Text and attribute values are escaped when rendered.

use Nijhof\Html\Attributes\ElementId;
use Nijhof\Html\Elements\Button;
use Nijhof\Html\Elements\Form;
use Nijhof\Html\Elements\Input;
use Nijhof\Html\Elements\Table;
use Nijhof\Html\Elements\TableBody;
use Nijhof\Html\Elements\TableCell;
use Nijhof\Html\Elements\TableHead;
use Nijhof\Html\Elements\TableHeaderCell;
use Nijhof\Html\Elements\TableRow;
use Nijhof\Html\Text;
use Nijhof\Html\Values\ButtonType;
use Nijhof\Html\Values\FormFieldName;
use Nijhof\Html\Values\RouteUrl;

$query = Input::search(ElementId::of('query'), FormFieldName::of('query'))
    ->withPlaceholder('Search')
    ->withValue('Ada');

echo Form::get(
    RouteUrl::of('/search'),
    $query,
    Button::text(ButtonType::SUBMIT, 'Search')
)->render();

echo Table::of(
    TableHead::of(TableRow::of(TableHeaderCell::text('Name'))),
    TableBody::of(TableRow::of(TableCell::text('Ada Lovelace')))
)->render();

Development

composer install
composer analyse
composer test

License

This package is licensed under the MIT License.