This project is DEPRECATED and not being maintained anymore.
A dynamic builder of tag elements
Add to your composer.json:
"require": {
"tagmaker/tagmaker": "~0.5"
}
$element = TagMaker::create('a', 'Link', array('class' => 'btn'));
echo $element; // Output: '<a class="btn">Link</a>'
$element->set_href('#');
$element->append_class('btn-large');
echo $element; // Output: '<a href="#" class="btn btn-large">Link</a>'
$element = TagMaker::create('form.form-vertical#new-post[name=new-post,method=post]');
echo $element; // Output: '<form name="new-post" method="post" class="form-vertical" id="new-post"></form>'
$element = TagMaker::create('.row.span6#main {Lorem ipsum}');
echo $element; // Output: '<div class="row span6" id="main">Lorem ipsum</div>'
$element = TagMaker::create('.content', 'Lorem ipsum');
$element->set_id('main-content');
$element->prepend_class('span6');
// Output: <div class="span6 content" id="main-content">Lorem ipsum</div>
Available magic methods for attribute manipulation are:
append_{$attribute}($value)
, prepend_{$attribute}($value)
, set_{$attribute}($value)
, add_{$attribute}()
and get_{$attribute}()
.
add_{$attribute}()
tries to add an attribute to an Element, throwing a ExistentAttributeException if that attribute already exists.
set_{$attribute}()
add an attribute to an Element, overriding it if already exists.
TagMaker provides a way to decodes single HTML elements and transforms it to a TagMaker\Element
. Examples:
$element = TagMaker::decode('<div class="main" id="content">Lorem ipsum...</div>');
// Will create a TagMaker\Element based at the given HTML
Decoder does not support multiple elements (see Limitations).
The actual version does not support multiple elements.
Is pretended to support multiple elements (for decoding and creation) after 1.0 version.