PHP code example of livy / cyrus

1. Go to this page and download the library: Download livy/cyrus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

livy / cyrus example snippets


$element = new Cyrus;

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

> $element = Cyrus::open(); // this is the same as `$element = new Cyrus;`
> 

$fakeTag = new Cyrus;

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

// <fake-tag>
// This isn't a real tag, but it's rendered anyway!
// </fake-tag>

$test = new Cyrus('test-1');
// or...
$test = Cyrus::open('test-1');
// <div class="test-1"></div>

$nested = new Cyrus;

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

// <div class="parent">
//    <span class="child">I'm a child!</span>
// </div>

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

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

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

// <div class="parent">
//    <span class="child">I'm a child!</span>
// </div>

$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();

// <div class="parent">
//    <div class="child">I've been inserted</div>
// </div>

$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();

//<div class="wrapper">
//	<div class="level-1">
//		<div class="level-2">Content</div>
//	</div>
//</div>		


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

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

$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');

$element->setAttr('data-target', 'menu')->display();
// <div data-target="menu"></div>
$element->setAttr('data-target', false)->display();
// <div></div>

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

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

$element->class('outside')
  ->content('hello')
  ->o()->class('inside')->content(false)->c();
// <div class="outside">hello</div>