PHPackages                             livy/cyrus - 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. livy/cyrus

ActiveLibrary

livy/cyrus
==========

A simple, object-oriented HTML templating/generation engine. Named for the ancient Roman architect.

1.7.2(8y ago)01.5k[4 issues](https://github.com/alwaysblank/cyrus/issues)MITPHP

Since May 16Pushed 8y agoCompare

[ Source](https://github.com/alwaysblank/cyrus)[ Packagist](https://packagist.org/packages/livy/cyrus)[ RSS](/packages/livy-cyrus/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (20)Used By (0)

Cyrus
=====

[](#cyrus)

### a simple object-based HTML generator

[](#a-simple-object-based-html-generator)

Usage
-----

[](#usage)

Cyrus uses objects and method chaining to construct semantic HTML elements and then output them for you.

The basic process is as follows:

```
$element = new Cyrus;

$element->setEl('h1')->setClass('headline-el')->addContent('This is a Headline!')->display();
```

> **Note:** You can also instatiate Cyrus with its internal factory:
>
> ```
> $element = Cyrus::open(); // this is the same as `$element = new Cyrus;`
> ```

The above code will print out the following:

```
This is a Headline!
```

It supports any tag type, even ones you made up:

```
$fakeTag = new Cyrus;

$fakeTag->setEl('fake-tag')->setContent('This isn\'t a real tag, but it\'s rendered anyway!')->display();

//
// This isn't a real tag, but it's rendered anyway!
//
```

In general the order you chain methods in doesn't matter: `$element->setClass('a-class')->setEl('p')` is function equivalent to `$element->setEl('p')->setClass('a-class')`. There are, however, a few exceptions:

- Nesting (see next section) requires `openChild` at the beginning fo a child element and `closeChild` at the end: Any other order will cause Cyrus to fail.
- Methods that overwrite content (i.e. `setEl`) will overwrite the actions of previous calls in the chain (unless separated by child barriers).
- Calls to `construct` or `display` should always come last. Since they don't return the current object, they'll break the chain, and attempting to chain other things after them will cause some errors.

#### Initial Class

[](#initial-class)

When instantiating Cyrus, you can specify a class for the primary element, by doing the following:

```
$test = new Cyrus('test-1');
// or...
$test = Cyrus::open('test-1');
//
```

### Nesting

[](#nesting)

You can nest elements inside of one another using the `openChild` and `closeChild` methods:

```
$nested = new Cyrus;

$nested->setClass('parent')
    ->openChild()->setEl('span')->setClass('child')->addContent("I'm a child!")->closeChild()
->display();

//
//    I'm a child!
//
```

#### Object Nesting

[](#object-nesting)

If you pass a Cyrus object to `addContent`, that object will be inserted as content and automatically expanded.

```
$parent = new Cyrus;
$child = new Cyrus;

$child->setClass('child')->setEl('span')->addContent("I'm a child");

$parent->setClass('parent')->addContent($child)->display();

//
//    I'm a child!
//
```

#### Advanced Nesting

[](#advanced-nesting)

You can also nest items after a chain has been terminated by using the `nest` method an assigning an ID when calling `openChild`. This is especially useful if, say, you want to insert (or not) content based on a conditional without resorting to creating an entirely separate Cyrus instatiation:

```
$nestedAgain = new Cyrus;

$nestedAgain->setClass('parent')->openChild('childID')->setClass('child')->closeChild();

if(true) :
    $nestedAgain->nest('childID')->addContent("I've been inserted!")->closeChild();
endif;

$nestedAgain->display();

//
//    I've been inserted
//
```

You must point to nested elements directly, and define the entire path if they are nested more than one level down. You can do this by delimiting the ids with `/`, like so:

```
$deepNesting = new Cyrus;

$deepNesting->setClass('wrapper')
	->openChild('level1')->setClass('level-1')
		->openChild('level2')->setClass('level-2')->closeChild()
	->closeChild();

$deepNesting->nest('level1/level2')->addContent('Content')->closeChild()->closeChild();

$deepNesting->display();

//
//
//		Content
//
//
```

It's important to note that when opening up nesting contexts like this, *all* children must be closed. There are a two convenience methods that can help you with this, `closeChildren` and `closeAll`. `closeChildren` takes an integer as an argument, and will close a number children equal to that integer. `closeAll` takes no arguments, and will close all chilren that are open in the current context.

### Methods

[](#methods)

To learn how methods operate, have a look at the source files (`./src`). Each method is well documented.

The follow will cover some special functionality and edge cases.

#### Short forms

[](#short-forms)

Any method that begins with "set" can be called in a shortened form, i.e. you can call `setClass` as just `class`.

```
$element->el('blockquote');
// is equivalent to...
$element->setEl('blockquote');

$element->attr('target', 'new');
// is equivalent to...
$element->setAttr('target', 'new);
```

Most nesting functions have short forms as well:

```
$el->o();
// is equivalent to...
$el->openChild();

$el->c();
// is equivalent to...
$el->closeChild();

$el->ca();
// is equivalent to...
$el->closeAll();

$el->n('something');
// is equivalent to...
$el->nest('something');
```

#### Advanced Attribute Manipulation

[](#advanced-attribute-manipulation)

##### Unset Attribute

[](#unset-attribute)

If you find you want to unset an attribute, call `setAttr` on it with the `false` argument:

```
$element->setAttr('data-target', 'menu')->display();
//
$element->setAttr('data-target', false)->display();
//
```

##### Valueless Attributes

[](#valueless-attributes)

If you want to set an attribute that doesn't have a value--i.e. `checked`--you can do so by calling `setAttr` with the `true` argument:

```
$element->setEl('input')->setAttr('type', 'radio')->setAttr('checked', true);
//
```

#### setAttr, etc

[](#setattr-etc)

`setAttr` and all of its aliased methods (i.e. `setClass`, `setURL`, etc) stack up whatever is passed to the same attribute--they don't overwrite anything. The only exception to this is if you pass `false` as an argument to `setAttr`, as this will completely remove that attribute from the element.

This value stacking means that the following statements are equivalent:

```
$element->setAttr('class', 'test1')->setClass('test2');
// is equivalent to...
$element->setClass('test1 test2');
```

#### Negate Element with False Content

[](#negate-element-with-false-content)

Using `setContent` to set the only content of an element explictly to bool `false` will cause that element to not be generated. This can be useful if you want elements to only appear if they have content. In order for the element to be negated, the following must be true:

- The element has only one item of content (i.e. count($this-&gt;content) === 1)
- That content item is exactly equal to bool `false` (not a *falsey value*, but the literal boolean `false`)
- The element in question is not a self-closing element

Examples:

```
$element->class('outside')
  ->content('hello')
  ->o()->class('inside')->content(false)->c();
// hello
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~38 days

Recently: every ~147 days

Total

18

Last Release

3001d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/45ef59bc24058cd989f522d8a6f8cc9b9aa31721b765d2b8552500dcc268e15d?d=identicon)[alwaysblank](/maintainers/alwaysblank)

---

Top Contributors

[![alwaysblank](https://avatars.githubusercontent.com/u/23412884?v=4)](https://github.com/alwaysblank "alwaysblank (41 commits)")

---

Tags

html

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/livy-cyrus/health.svg)

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

###  Alternatives

[ezyang/htmlpurifier

Standards compliant HTML filter written in PHP

3.4k327.6M445](/packages/ezyang-htmlpurifier)[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.5k34.7M186](/packages/phpoffice-phpword)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k28.6M199](/packages/league-html-to-markdown)[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k25.5M88](/packages/picqer-php-barcode-generator)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48419.5M75](/packages/soundasleep-html2text)

PHPackages © 2026

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