A simple library to generate HTML fragments with a jquery-like interface.
This library does not parse HTML, and it does not provide element lookup via selectors or otherwise. It is focused on building simple HTML fragments, for example embed codes, while taking care of proper escaping and other simple syntax rules. Its purpose is to replace manual concatenation of strings.
function generateBarcodeHtml( $barcode ) {
$generator = new BarcodeGeneratorHTML();
$htmlCode = $generator->getBarcode( $$barcode->toString(), $$barcode->getType(), 1, 45 );
$el = Html::element('div');
$el->addClass('barcode-container');
Html::element('div')
->addClass('barcode-bars')
->html( $htmlCode )
->appendTo($el);
Html::element('div')
->addClass('barcode-number')
->text( $normalizedValue->toString() )
->appendTo($el);
return $el;
}
public function generateMenu(array $items) {
$ul = Html::element('ul');
foreach ( $this->items as $item ) {
$li = Html::element('li')
->appendTo( $ul )
->toggleClass('active', $item['id'] === $this->activeId);
Html::element('a')
->attr('href', '/' . $item['url_key'] . '.html')
->text( $item['title'] )
->appendTo( $li );
}
return (string)$ul;
}
Creates an element.
Creates a comment node.
Creates a text node.
Add the new element as the last child.
Add the element as the targets last child.
Add the new element as the first child.
Add the element as the targets first child.
Sets the attribute with the given name and value.
Returns the attribute with the given name.
Returns all attributes as an associative array.
Removes the attribute with the given name.
Adds a raw html string as a child.
Returns the html representation of the content.
Returns the node as html.
Adds a text node.
Returns the text contents of this node including its descendants.
Add one or more classes. Multiple classes are separated by a space.
Returns true if the element has the class.
Remove or add the class.
Use $el->attr("class")
Returns the tag name.
Changes the tag name.