Search by

wert1209yt / htmlman

Wert1209yt

Object-oriented HTML generator and declarative UI builder for PHP without extra files.

Package info

github.com/Wert1209yt/htmlman

pkg:composer/wert1209yt/htmlman

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-09-21 15:25 UTC

This package is auto-updated.

Last update: 2026-09-23 06:47:04 UTC


README

Logo

PHP PHP

A lightweight PHP framework for efficient HTML generation.

Why us

  • Maximum OOP
  • Create HTML elements directly in PHP using the corresponding classes, for example: new P('Example!'), new Div([ new P('Example)])
  • Register your elements to simplify things: you can register a class associated with a div—complete with HTML classes, styles, and even a nested structure — and the engine will automatically locate the innermost element and inject the content there! (And WebComponents support)
  • Formatting your HTML structure via ->format() adds indentation to the element class and nested elements (by default, minified HTML without indentation is output).
  • Adding classes, IDs, and styles to elements is supported via ->class('example example-has-padding'), ->id('123'), and ->style('display: none;').
  • Slots out-of-the-box support via ->slot('slot') for simplifying development.
  • Support for all HTML5 elements, except obsolete ones, though you can register any obsolete element.
  • Auto-screening of content (can be disabled by ->raw() or on registering element can be disabled by default 'autoShielding' => false')
  • Compiler for your HtmlMan code.

How to get started

First, you need to install it via Composer:

composer require wert1209yt/htmlman

Usage in your project:

<?php
require_once 'vendor/autoload.php';

HtmlMan::init(); // Init will add all base HTML5 elements classes
?>

Register your custom elements classes

HtmlMan::register([
    'name' => 'Card',
    'autoShielding' => false, // auto-shielding can be disabled
    'tag' => 'div', // Or any html tag (WebComponents support)
    'class' => 'card',
    'id' => '123',
    'style' => [
        'background-color' => '#ffffff',
        'border' => '1px solid #ddd'
    ], // Or string 'background-color: #ffffff; border: 1px solid #ddd'

    // Element structure
    'structure' => new Main([
        (new Div([
            new P() // Will put content there
        ]))->class('card-body')
    ])
]);

Minimal (example):

HtmlMan::register([
    'name' => 'YourElement',
    'tag' => 'div'
])

Slots:

HtmlMan::register([
    'name' => 'Card',
    'autoShielding' => false, // auto-shielding can be disabled
    'tag' => 'div', // Or any html tag (WebComponents support)
    // Element structure
    'structure' => new Main([
        new Div([
            (new H1())->slot('header'),
            (new P())->slot('text'),
        ])
    ])
]);

Slots use:

new Card([
    'header' => 'Card',
    'text' => 'text'
]);

Base use

$div = new Div([ new P('Example)])

echo $div->format();

Add class, id or style:

$div = (new Div([ new P('Example)]))
       ->class('example')
       ->id('123')
       ->style('display: none');

You can add indents using formatting:

$html = (new Div([ new P('Example)]))
         ->format();

If you want link:

echo (new A('link'))
    ->href('https://github.com')
    ->target('_blank')
    ->class('link-style');

Compiler

A compiler is needed to compile your code for maximum efficiency: The compiler transforms your code into lightning-fast PHP; if there are external variables that your code utilizes, they will be used in the compiled code, the same applies to loops.

Compiling:

<?php
require_once __DIR__ . '/../vendor/autoload.php';

HtmlMan::init();
HtmlMan::register([
    'name' => 'Card',
    'tag' => 'div',
    'class' => 'card',
    'style' => 'border: 1px solid #ccc;',
    'structure' => new Main([ 
        (new P())->slot('text'),
        (new H1())->slot('header'),
    ])
]);

$header = 'Working!';
$text = 'HtmlMan is working!';

HtmlMan::ReadStart();

$card = new Card([
    'header' => $header,
    'text' => $text
]);

echo $card;
HtmlMan::Compile([
    'compilePath' => __DIR__ . '/compiledDir',
    'file'        => 'compiled.php'
]);

Compiled code:

<?php
// HtmlMan compiled code compiled.php

$slot_header_2 = htmlspecialchars((string)($header), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$slot_text_3 = htmlspecialchars((string)($text), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$card_1 = '<div class="card">' . "\n" . ('<main>
' . ('    <p>' . $slot_text_3 . '</p>
' . '    <h1>' . $slot_header_2 . '</h1>
') . '</main>
') . '</div>' . "\n";
$card = $card_1;

echo $card;

Using:

<?php
$header = 'Working!';
$text = 'HtmlMan is working!';

require('compiledDir/compiled.php');

Compiler is highly recommend to use.