PHPackages                             chh/jazz - 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. [Templating &amp; Views](/categories/templating)
4. /
5. chh/jazz

ActiveLibrary[Templating &amp; Views](/categories/templating)

chh/jazz
========

When you do need to generate HTML with PHP.

v1.0.1(14y ago)2042911MITPHPPHP &gt;=5.3.3

Since Mar 12Pushed 14y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (3)Used By (1)

Jazz
====

[](#jazz)

> When you absolutely, positively have to generate HTML within PHP Code.

Jazz is a very tiny library which turns a nested Array into HTML. You could call it a "DSL" if you want. It works well with PHP later than 5.3.3 but looks best with 5.4's new short array syntax.

I wrote Jazz, because there are always places where you have to generate a bit of HTML and don't want to use a template, for the sake of performance or simplicity.

At first you need only one tag, you think "Fine I'm using a String", and then you need to add an attribute, then a second one, maybe a third one. Then you find yourself in a big mess.

I've written plenty of those code bits, and I'm tired of it:

```
$html  = '';
$html .= '' . $this->getSomeListItems() . '';
$html .= '';

```

It's not only hard to grasp, but also plain ugly and also adding attributes, or adding other sub elements is cumbersome.

Now relax with some Jazz:

```
array_unshift($classes, "widget");

$attrs = [
    "class" => $classes,
    "id" => $id,
    "style" => "display: none;",
    "data-widget-name" => $widgetName
];

$html = Jazz::render(
    ["#div", $attrs, [
        ["#ul", $this->getSomeListItems()]
    ]]
);

```

It's in this case not shorter, but it's easily extendable, and the intent is clear.

Hello World
-----------

[](#hello-world)

```
