Mecha CMS

Mecha CMS blog and documentation.

Class Cell

Updated: Sunday, 07 August 2016

HTML markup constructor.

Added since version 1.1.3.

Base Constructor

Cell::unit('tag_1', 'Hello!', array('foo' => 'bar'));
Cell::unit('tag_2', "", array('foo' => 'bar'));
Cell::unit('tag_3', false, array('foo' => 'bar')); // self-closing HTML tag

Result:

<tag_1 foo="bar">Hello!</tag_1>
<tag_2 foo="bar"></tag_2>
<tag_3 foo="bar">

Options

Cell::unit($tag, $content = "", $attr = array(), $indent = 0);
ParameterDescription
$tagThe tag name.
$contentThe content of the HTML markup. Set to false if you want to make a self–closing HTML tag such as <img>
$attrThe HTML attributes. Each array key will becomes the HTML attributes, and the array value will becomes the HTML attribute value.
$indentAdd indentation at the beginning of the tag output.

Attributes

HTML5 data-* Attributes

Option 1:

Cell::unit('tag', "", array(
    'data-name' => 'John',
    'data-age' => 24
));

Option 2:

Cell::unit('tag', "", array(
    'data' => array(
        'name' => 'John',
        'age' => 24
    )
));

Result:

<tag data-name="John" data-age="24"></tag>
Classes

Option 1:

Cell::unit('tag', "", array(
    'class' => 'foo bar baz'
));

Option 2:

Cell::unit('tag', "", array(
    'class' => array(
        'foo',
        'bar',
        'baz'
    )
));

Result:

<tag class="foo bar baz"></tag>
Inline CSS

Option 1:

Cell::unit('tag', "", array(
    'style' => 'background-color: #000; color: #fff'
));

Option 2:

Cell::unit('tag', "", array(
    'style' => array(
        'background-color' => '#000',
        'color' => '#fff'
    )
));

Result:

<tag style="background-color:­ #000;­ color:­ #fff;"></tag>
Stand–Alone HTML Attributes
Cell::unit('tag', "", array(
    'selected' => true,
    'disabled' => true
));

Result:

<tag selected disabled></tag>

Shortcut

Most of the generated tag name from Cell::unit() can be created by the method itself as long as they are not registered yet by the Cell::add() method:

Cell::unit('div', 'Hello!', array('class' => 'foo'));

is equal to:

Cell::div('Hello!', array('class' => 'foo'));

Special Tag

<meta>

Cell::meta($name, $content, $attr, $indent);
Cell::link($href, $rel, $type, $attr, $indent);

<script>

Cell::script($src, $content, $indent);
Cell::script($attr, $content, $indent);

<a>

Cell::a($href, $text, $target, $attr, $indent);

<img>

Cell::img($src, $alt, $attr, $indent);

<ol>

Cell::ol($list = array(), $attr, $indent);

<ul>

Cell::ul($list = array(), $attr, $indent);

<hr>

Cell::hr($repeat = 1, $attr, $indent);

<br>

Cell::br($repeat = 1, $attr, $indent);

Custom Tag

Cell::add('foo', function($content = "", $attr = array(), $indent = 0) {
    return Cell::unit('foo', $content, $attr, $indent);
});

Usage:

Cell::foo('Hello!', array('bar' => 'baz'), 3);
Donation and Email Subscription