PHP code example of kylekatarnls / html-object
1. Go to this page and download the library: Download kylekatarnls/html-object 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/ */
kylekatarnls / html-object example snippets
echo Element::p('text')->class('foobar');
// <p class="foobar">text</p>
$list = List::ul(array('foo', 'bar'));
$link = Link::create('#', 'Someone');
$list->getChild(0)->addClass('active')->setValue('by '.$link);
// <ul>
// <li class="active">foo</li>
// <li>by <a href="#">Someone</a></li>
// </ul>
echo Link::create('#foo', 'link')->class('btn btn-success')->blank();
// <a href="#foo" class="btn btn-primary" target="_blank">link</a>
$element = Element::figure();
$element->nest('content') // <figure>content</figure>
$element->nest('p', 'content') // <figure><p>content</p></figure>
$image = Image::create('img.jpg')->alt('foo'); // <img src="img.jpg" alt="foo" />
$element->setChild($image, 'thumb');
$element->getChild('thumb') // HtmlObject\Image
$element->nest(array(
'caption' => Element::figcaption()->nest(array(
'text' => Element::p('foobar'),
)),
));
$element->getChild('caption.text')->getValue() // foobar
// OR
$element->captionText->getValue() // foobar
$element->captionText->getParent(0) // figure->caption
$element->captionText->getParent(1) // figure
$element->wrap('div') // <div><figure>...</figure></div>
$element->wrapValue('div') // <figure><div>...</div></figure>
protected function injectProperties()
{
return array(
'href' => $this->url,
);
}
$mediaObject = Element::div([
'title' => Element::h2('John Doe'),
'body' => Element::div(),
]);
echo $mediaObject->openOn('body').'My name is John Doe'.$mediaObject->close();
Tag::$config['doctype'] = '{xhtml|html}';