2017-25 © Pedro Peláez
 

library html

A helper package for generating HTML5 tags

image

studiow/html

A helper package for generating HTML5 tags

  • Friday, October 30, 2015
  • by studiowbe
  • Repository
  • 0 Watchers
  • 2 Stars
  • 125 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 23 % Grown

The README.md

html

A helper package for generating HTML5 tags, (*1)

Usage

Installation

The easiest way to install this package is using composer: ``` bash composer require studiow/html, (*2)


### Basic usage Generating HTML tags with this package is pretty easy: ```php // Create the element $link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]); // Output echo (string) $link; // prints <a href="/documents">Documents</a>

Getting and setting attributes

Working with attributes is easy too:, (*3)

// Create the element
$link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]);

// Set an attribute
$link->setAttribute('title', 'Go to documents');

// Get the value for an attribute
$link->getAttribute('title');  // returns  'Go to documents'
$link->getAttribute('attr_not_set');  // returns  null

// Remove an attribute
$link->removeAttribute('title');

A touch of class

Working with classes works pretty much as you'd expect:, (*4)

// Create the element
$link = new \Studiow\HTML\Element("a", "Documents", ["href"=>"/documents"]);

// Add a single class
$link->addClass("button");

// Add multiple classes seperated by a space
$link->addClass("button button-documents");

// Remove a class
$link->removeClass("button");

// Check if the element has a certain class
$link->hasClass("button-documents");

Method chaining

You can go ahead and chain the methods together, (*5)

$link = new Studiow\HTML\Element("a");
$link->setInnerHTML("Documents")
        ->setAttribute("href", "/documents")
        ->addClass("button")
        ->addClass("button-documents")
        ->setAttribute('title', "Go to documents");
echo (string) $link; // Outputs <a href="/documents" class="button button-documents" title="Go to documents">Documents</a>

Known Issues

Case (in)sensitve

HTML5 attributes are supposed to be case-insensitive, but here they are case-sensitive. Lowercase recommended!, (*6)

Where is getChildren() etc.?

This package is by no means meant as a tool to generate large pieces of HTML. While you can use an Element as the innerHTML of another Element it will be converted to text when you do this., (*7)

If you find yourself rendering large pieces of HTML within a PHP script, you'd probably be better of using a template system., (*8)

The Versions

30/10 2015

dev-master

9999999-dev

A helper package for generating HTML5 tags

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

30/10 2015

v1.0.1

1.0.1.0

A helper package for generating HTML5 tags

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

21/07 2015

v1.0.0

1.0.0.0

A helper package for generating HTML5 tags

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires