Download the PHP package canteen/html5 without Composer
On this page you can find all versions of the php package canteen/html5. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download canteen/html5
More information about canteen/html5
Files in canteen/html5
Informations about the package html5
Canteen HTML5
Create dynamic, well-formatted HTML5 markup with a simple an intuitive PHP API. This is a fork/rewrite of the Gagawa project. CanteenHTML5 is a concise, flexible and easy to remember API which makes it possible to create simple markup (such as a link) or more complex structures (such a table, document or nested list). All tags and attribute names are validated against the current HTML5 specification.
For documentation of the codebase, please see Canteen HTML5 docs.
Requirements
This library requires a webserver running PHP 5.3+. Also, the root namespace for the library is Canteen\HTML5
.
Installation
Install is available using Composer.
Including using the Composer autoloader.
Usage
Basic
To create an HTML node, simply call global html
method, passing in the tag name and then any attributes.
All of these examples would output:
Adding Attributes
There are dfferent ways to add attributes for HTML container nodes such as <p>
, <div>
, or in the example below, <nav>
.
-
Part of the tag
-
As an associative array
-
As a shorthand string
- As an property methods
All of these examples output the same markup:
Adding Nested Elements
Any HTML5 container tags (such as <p>
, <span>
, or <div>
) can have child elements. These elements can be strings or other HTML5 element objects.
Alternatively, use the addChild
method for any container tag.
Or appendTo
to target a container to be added to:
All examples would output:
CSS Selectors
Tag names can optionally have CSS-style class and id selectors:
API Documentation
For self-closing elements (e.g. <br>
, <img>
)
$tag
{string} The name of the valid HTML5 element which can contain CSS selectors or short-hand attribute string.$attributes
{array | string} (optional) Collection of element attributes
Returns a Canteen\HTML5\Node
object.
Node Methods
setAttribute($name, $value)
Set an attribute by name and value.setAttributes($values)
Set an associative array of name/value pairs.setData($name, $value)
Set data-* fields on the HTML5 element.getData($name)
Get the data-* field on the HTML5 element.appendTo(NodeContainer $container)
Add the element to the end of a container element.prependTo(NodeContainer $container)
Add the element to the beginning of a container element.
For container HTML elements (e.g. <p>
, <div>
)
$tag
{string} The name of the valid HTML5 element which can contain CSS selectors or short-hand attribute string.$contents
{string | Node | NodeContainer} (optional) The string of the contents of the tag, or another element created byhtml()
$attributes
{array | string} (optional) Collection of element attributes
Returns a Canteen\HTML5\NodeContainer
object.
NodeContainer Methods (extends Node
)
addChild($node)
Add aNode
object to the bottom of the collection of nodesaddChildAt($node, $index)
Add aNode
object at a specific zero-based indexremoveChild($node)
Remove a particular node from the containerremoveChildAt($index)
Remove a node by zero-based indexremoveChildren()
Remove all children from the containergetChildren()
Get the collection of allNode
objectsgetChildAt($index)
Get aNode
object at a specific index
Additional Components
Document
The Document
object is used for creating a bare-bones HTML5 document.
$title
{string} (optional) The title of the document$charset
{string} (optional) The HTML character set to use$beautify
{boolean} (optional) If the output should be an indented work of art.
Properties
head
{NodeContainer} The document's<head>
elementbody
{NodeContainer} The document's<body>
elementtitle
{NodeContainer} The document's<title>
element
SimpleList
The SimpleList
for conveniently creating <ul>
and <ol>
elements.
$elements
{array} The collection of strings or other HTML elements$attributes
{array | string} (optional) Collection of element attributes$type
{string} (optional) A value of either "ul" or "ol"
Table
The Table
object is used for creating <table>
elements.
$data
{array} The collection of associative-arrays with key/value pairs$headers
{array} (optional) The names of the header labels$checkbox
{string} (optional) The name of the key name in the data to replace with a checkbox, for instance "id"
Rebuild Documentation
This library is auto-documented using YUIDoc. To install YUIDoc, run sudo npm install yuidocjs
. Also, this requires the project CanteenTheme be checked-out along-side this repository. To rebuild the docs, run the ant task from the command-line.
License
Copyright (c) 2013 Matt Karl
Released under the MIT License.