PHPackages                             maxonfjvipon/phtml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. maxonfjvipon/phtml

ActiveLibrary

maxonfjvipon/phtml
==================

Pure object-oriented HTML construction templating library with functional interface

0.0.3(3y ago)321[5 issues](https://github.com/maxonfjvipon/phtml/issues)MITPHPPHP &gt;=8.0

Since Nov 4Pushed 3y ago2 watchersCompare

[ Source](https://github.com/maxonfjvipon/phtml)[ Packagist](https://packagist.org/packages/maxonfjvipon/phtml)[ RSS](/packages/maxonfjvipon-phtml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (0)

phtml
=====

[](#phtml)

phtml is pure object-oriented HTML construction templating library for PHP with functional interface, inspired by [JavaTags](https://github.com/manlioGit/javatags) and [ScalaTags](https://github.com/lihaoyi/scalatags).

[![EO principles respected here](https://camo.githubusercontent.com/5c7a27b75a8da4be52680df944abec4ccc4d0151df036e0793b8c9b16cbe3d1e/68747470733a2f2f7777772e656c6567616e746f626a656374732e6f72672f62616467652e737667)](https://www.elegantobjects.org)[![DevOps By Rultor.com](https://camo.githubusercontent.com/dceb8d6196b97583c084afeb49d656aa9184b581ba1ca6388681e0202642c143/687474703a2f2f7777772e72756c746f722e636f6d2f622f6d61786f6e666a7669706f6e2f7068746d6c)](http://www.rultor.com/p/maxonfjvipon/phtml)

[![Composer](https://github.com/maxonfjvipon/phtml/actions/workflows/composer.yml/badge.svg)](https://github.com/maxonfjvipon/phtml/actions/workflows/composer.yml)[![codecov](https://camo.githubusercontent.com/8a22ae2a427a2e7e1668f47b91db10e59d13913599ad874a42e76893d5cc8b04/68747470733a2f2f636f6465636f762e696f2f6769746875622f6d61786f6e666a7669706f6e2f7068746d6c2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d513132324d575054384a)](https://codecov.io/github/maxonfjvipon/phtml)[![Hits-of-Code](https://camo.githubusercontent.com/3f8e04eb1e95dd41c43704990a44e06ba39bed37ffe87a56fe326465ec2576a1/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f6d61786f6e666a7669706f6e2f7068746d6c3f6272616e63683d6d6173746572)](https://hitsofcode.com/github/maxonfjvipon/phtml/view?branch=master)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](https://github.com/maxonfjvipon/phtml/blob/master/LICENSE)[![Tag](https://camo.githubusercontent.com/20c52c89e0676ee708adcfc150376bed33f10dbceefdf50906326c63e249dad0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6d61786f6e666a7669706f6e2f7068746d6c2e737667)](https://github.com/maxonfjvipon/phtml/releases)

This fragment:

```
use Maxonfjvipon\Phtml\at;
use function Maxonfjvipon\Phtml\{html5, attr, head, meta, title, link, text};

html5(attr([at::lang => 'en']),
  head(
    meta(attr([at::http_equiv => 'Content-Type', at::content => 'text/html', at::charset => 'UTF-8'])),
    title(text("Title")),
    link(attr(["href" => "/css/custom.css", "rel" => "stylesheet"]))
  )
)->asString();
```

will be turned into this html:

```
>

    Title

```

Getting started:
----------------

[](#getting-started)

### Requirements

[](#requirements)

- PHP &gt;= 8.0

### Installation

[](#installation)

```
composer require maxonfjvipon/phtml

```

Examples
--------

[](#examples)

### basic:

[](#basic)

Library provides all html tags as functions with only one exception - ``. PHP does not allow you to create function named `var` since this word is reserved. So to create `` tag use `_var` function

#### ***(if you know more elegant way to handle this `` - please create an issue)***

[](#if-you-know-more-elegant-way-to-handle-this-varvar---please-create-an-issue)

This code

```
use function Maxonfjvipon\Phtml\{html5, head, body, div, _var, text};

html5(
  head(),
  body(
    div(
      _var(text("Hello world!"))
    )
  )
)->asString();
```

will render to you this html:

```
>

      Hello world!

```

### Attributes:

[](#attributes)

To add attributes to your tag you should use `attr` function. Function accepts an array with arguments. Array may has `'key' => 'value'` and just `'value'` elements:

```
use function Maxonfjvipon\Phtml\{a, attr};

a(attr(['href' => '/some/url', "download"]))->asString(); //
```

Attributes will be rendered only if they are at the first place. Other attributes on other places will be ignored.

```
use function Maxonfjvipon\Phtml\{a, attr};

div(attr(['class' => 'div']), div())->asString(); //
div(div(), attr(['class' => 'div']))->asString(); //
```

Library provides helper class `Maxonfjvipon\Phtml\at` that contains all existed html attributes as consts. You can use it in this way:

```
use Maxonfjvipon\Phtml\at;
use function Maxonfjvipon\Phtml\{html5, attr};

html5(attr([at::lang => "en"]))->asString(); //
```

#### Note!

[](#note)

`at::class` will return you `\Maxonfjvipon\Phtml\at` instead of expected `'class'` (since `::class` is reserved by PHP)

#### ***(if it's possible to override this `::class` and you know how to do it - please create an issue)***

[](#if-its-possible-to-override-this-class-and-you-know-how-to-do-it---please-create-an-issue)

To get `'class'` string from `at` you can do `at::_class` or `at::$class`. Or you can just write it manually

```
use Maxonfjvipon\Phtml\at;
use function Maxonfjvipon\Phtml\{html5, attr};

attr([at::class => 'main'])->asString(); // \Maxonfjvipon\Phtml\at='main'
attr(['class' => 'main'])->asString(); // class='main'
attr([at::$class => 'main'])->asString(); // class='main'
attr([at::_class => 'main'])->asString(); // class='main'
```

### Helpers:

[](#helpers)

#### Custom tags

[](#custom-tags)

You can create your custom tags using 2 helper functions: `paired` and `unpaired`:

```
use function Maxonfjvipon\Phtml\{unpaired, paired};

unpaired('somebody', attr(['class' => 'custom unpaired']))->asString(); //
paired('somebody', attr(['class' => 'custom paired']))->asString(); //
```

If you want to add many tags (for example from array) you can use `tags` function:

```
use function Maxonfjvipon\Phtml\{tags, div, unpaired, link};

tags(div(), unpaired('my'), link())->asString(); //
```

#### Strings, Tags and Texts

[](#strings-tags-and-texts)

Library is based on `Maxonfjvipon\ElegantElephant\Txt` class from [ElegantElephant](https://github.com/maxonfjvipon/ElegantElephant). So besides attributes every paired tag can accept other tags, strings and Texts.

This tag:

```
use Maxonfjvipon\ElegantElephant\TxtOf;
use function Maxonfjvipon\Phtml\{div, link};

div(attr(['class' => 'main']),
  link(), // other tag
  TxtOf::str('text'), // Text
  text("alias"), // wrap string to Maxonfjvipon\ElegantElephant\Txt
  "just string",
)->asString();
```

will be turned into:

```

  \n
  text\n
  alias\n
  just string\n

```

#### Import

[](#import)

If you want to use all available tags and functions you have to add this import.

#### ***(if you know how to make this whole import shorter - please create an issue)***

[](#if-you-know-how-to-make-this-whole-import-shorter---please-create-an-issue)

Keep in mind that some tag functions have the same name as built in php functions (like `\header()`, `\time()`, etc). So make sure that you have imported these functions before using them.

```
use function Maxonfjvipon\Phtml\{
    text,
    unpaired,
    paired,
    a,
    abbr,
    address,
    article,
    aside,
    audio,
    b,
    bdi,
    ddo,
    blockquote,
    body,
    button,
    canvas,
    caption,
    cite,
    code,
    colgroup,
    data,
    datalist,
    dd,
    del,
    dfn,
    div,
    dl,
    dt,
    em,
    fieldset,
    figcaption,
    figure,
    footer,
    form,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    head,
    header,
    i,
    iframe,
    ins,
    kbd,
    label,
    legend,
    li,
    main,
    map,
    mark,
    meter,
    nav,
    noscript,
    object,
    ol,
    optgroup,
    option,
    output,
    p,
    pre,
    progress,
    q,
    rb,
    rp,
    rt,
    rtc,
    ruby,
    s,
    samp,
    script,
    section,
    select,
    small,
    span,
    strong,
    style,
    sub,
    sup,
    table,
    tbody,
    td,
    template,
    textarea,
    tfoot,
    th,
    thead,
    time,
    title,
    tr,
    u,
    ul,
    video,
    attr,
    tags,
    br,
    html5,
    area,
    base,
    col,
    command,
    embed,
    hr,
    img,
    input,
    link,
    meta,
    param,
    source,
    track,
    wbr,
    _var,
    xmp
};
```

### Contribution

[](#contribution)

Fork repository, make changes, send a pull request. To avoid frustration, before sending your pull request please run:

```
$ ./pre-push.sh
```

And make sure you have no errors.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

1279d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/553059dc46ea6e67ba5b9e1de4b9056af3c1892ab4f4576cab0687143e00b6f9?d=identicon)[maxonfjvipon](/maintainers/maxonfjvipon)

---

Top Contributors

[![maxonfjvipon](https://avatars.githubusercontent.com/u/37025995?v=4)](https://github.com/maxonfjvipon "maxonfjvipon (41 commits)")[![rultor](https://avatars.githubusercontent.com/u/8086956?v=4)](https://github.com/rultor "rultor (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/maxonfjvipon-phtml/health.svg)

```
[![Health](https://phpackages.com/badges/maxonfjvipon-phtml/health.svg)](https://phpackages.com/packages/maxonfjvipon-phtml)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
