leaf
PHP DOM Generator, (*1)
install
composer require unercloud/leaf
, (*2)
simple example
$l = new \Undercloud\Leaf();
$l->el('html')
->el('body')
->el('h1#id.classname','Heading')->end
->el('p',array('class' => 'article'),'Lorem ipsum...')->end
->el('input:text',array('value'=>'text'))
->end
->end;
echo $l;
constructor
$l = new \Undercloud\Leaf(
array(
//format tree
'format' => true,
//indent in formatted tree, default two spaces
'indent' => ' ',
//define own single tags
'selfclosing' => array(...)
)
);
methods
el - create element, (*3)
$l->el('tag')
or, (*4)
$l->el('tag','text')
or, (*5)
$l->el('tag',array $attr)
or, (*6)
$l->el('tag',array $attr,'text')
You can combine tag with #id and .classname shortcut e.g., (*7)
$l->el('span#id.classname.anotherclass')
Input[type] attr helper for button,checkbox,file,hidden,image,password,radio,reset,submit,text e.g., (*8)
$l->el('input:text')
Single attr helper for 'checked','disabled','readonly','required','multiple e.g., (*9)
$l->el('select:multiple')
text - create text node, (*10)
$l->text('any content')
raw - add raw data wihout escaping, (*11)
$l->raw('raw content')
end - close tag, (*12)
$l->end() // or $l->end
helpers
init - create instance, (*13)
Undercloud\Leaf::init($opt = array())
escape - escape special chars, (*14)
Undercloud\Leaf::escape($s)