Download the PHP package gin0115/elmishphp-html without Composer
On this page you can find all versions of the php package gin0115/elmishphp-html. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gin0115/elmishphp-html
More information about gin0115/elmishphp-html
Files in gin0115/elmishphp-html
Package elmishphp-html
Short Description A functional based library for creating HTML in PHP, heavily inspired by the ELM HTML package
License GPL-2.0-or-later
Homepage https://github.com/gin0115/ElmishPHP-HTML
Informations about the package elmishphp-html
Elmish PHP — HTML
A functional library for creating HTML in PHP, heavily inspired by Elm's Html package. Each element is a typed value object with __toString — compose them with curried functions, render by stringification.
Why
Erm, next question........ok fine, why not. I really enjoyed ELMs approach to creating HTML and have played around with this idea before (Functional WP Plugin).
Install
Then the usual require 'vendor/autoload.php' and you're good to go.
How it works
Each HTML tag is a curried function. The first call passes attributes, the second passes children. Every function returns a typed object that knows how to render itself.
Elm-style formatting
For longer trees, leading-comma style mirrors elm-format:
Text content
| escapes? | use for | |
|---|---|---|
text('...') |
yes | the default for any string |
raw('<b>x</b>') |
no | pre-rendered HTML you trust |
bare 'string' |
yes (auto) | shorthand for text('string') as a child |
Attributes
Attributes are an associative array. Three forms:
All attribute values are HTML-escaped. Keys are not (they're under your control).
Void elements
Void elements take attributes only — no second call for children:
The void set: br, hr, img, input, wbr, col, source, track.
Custom tags via node()
For anything not in the built-in set:
Type hierarchy
Everything renderable shares a small interface tree — useful for categorisation and type-narrowing in your own code:
Every element function returns its concrete typed class (e.g. div(...)(...) returns Gin0115\ElmishPHP\HTML\Element\Div), so you can instanceof BlockElement or pass them around with full type info.
Supported tags
77 standard HTML elements out of the box.
| Category | Tags |
|---|---|
| Block | div, p, h1–h6, pre, blockquote, ul, ol, li, dl, dt, dd, figure, figcaption, hr |
| Inline | span, a, strong, em, small, b, i, u, mark, code, kbd, samp, sub, sup, time, abbr, cite, q, br, wbr |
| Sectioning | header, footer, main, nav, section, article, aside |
| Form | form, fieldset, legend, label, button, select, optgroup, option, textarea, input |
| Table | table, caption, colgroup, thead, tbody, tfoot, tr, td, th, col |
| Media | img, iframe, video, audio, canvas, picture, source, track |
| Interactive | details, summary, dialog |
For anything else, use node('tag-name', ...).
Tests
PHPUnit (unit / behaviour):
Playwright (browser-driven E2E against the kitchen-sink fixtures):
The kitchen-sink fixture at tests/e2e/views/kitchen-sink.php exercises every category — visit http://localhost:57893/?fixture=kitchen-sink while the server is up.
Requirements
- PHP 8.2+
- (optional) Docker + Node for the e2e suite
License
GPL-2.0-or-later