Cyrus

Links
Examples
Tech
  • PHP

Cyrus is a tool for creating HTML with PHP. It’s not really a templating language, more a sort of wierd recreation of the DOM. I created it because I wanted a way to generate HTML using PHP object method chaining. It’s a visually logical way of showing what gets generated, and it allows for programatically affecting what HTML is generated without wrapping raw tags in PHP.

$element = new Livy\Cyrus;
$element->class('this-is-the-class')->content('Here is some content!')->display();
<div class="this-is-the-class">Here is some content!</div>

You can also generate more heavily nested elements:

$nest = new Livy\Cyrus;
$nest->class('wrapper')
    ->o()->el('h1')->content('Welcome')->c()
    ->o()->el('p')->content("You've arrived at my web site!")->c()
->c()->display();
<div class="wrapper">
    <h1 class="h1">Welcome</h1>
    <p>You've arrived at my web site!</p>
</div>

nest() allows allows you to nest elements even after you’ve closed an element:

$list = new Livy\Cryus;
$list->class('wrapper')
    ->o('inner')->el('ul')->ca();

foreach (['one', 'two', 'three'] as $item) :
    $list->n('inner')->o()->el('li')->content($item)->ca();
endforeach;

$list->display();
<div class="wrapper">
	<ul>
		<li>one</li>
		<li>two</li>
		<li>three</li>
	</ul>
</div>