Zend Framework 2 (zf2) view helper plugin to use html tags like objects and to render them.

Installs: 3 163

Dependents: 2

Stars: 1

Watchers: 1

Forks: 2

Open Issues: 1

1.1.1 2015-01-19 21:54 UTC


You want HTML tags as objects?

You want surefire generated HTML tags and HTML attributes?

You want to generate HTML tags on the fly?

This module comes to the rescue!

Build Status Scrutinizer Code Quality Coverage Status HHVM Status SensioLabsInsight Latest Stable Version Dependency Status Total Downloads License

Zend Framework 2 view helper plugin for generating HTML tags. Use HTML tags as objects and manipulate HTML attributes and values.

  • Well tested. Besides unit tests and continuous integration/inspection this solution is also ready for production use.
  • Great foundations. Based on Zend Framework 2 and Easy Config
  • Every change is tracked. Want to know whats new? Take a look at
  • Listen to your ideas. Have a great idea? Bring your tested pull request or open a new issue. See


Installation of this module uses Composer. For Composer documentation, please refer to

Put the following into your composer.json

    "require": {
        "sandrokeil/html-element": "~1.0"

Then add Sake\HtmlElement to your ./config/application.config.php.


The usage is easy. Here is an example how to use the view helper


// assume we are in a template
echo $this->html('div', 'my content', array('id' => 'content', 'class' => 'box shadow'));

// or
$div = $this->html('div');
echo $div->setText('my content')
    ->setAttributes(array('id' => 'content', 'class' => 'box shadow'));

// to render HTML you can use
echo $div->enableHtml(true)
        $this->html('p')->setText('Hello World!')->appendClass('welcome');

// or
echo $this->html(
    $this->html('p')->setText('Hello World!')->appendClass('welcome'),
    array('id' => 'content', 'class' => 'box shadow'),

Performance tweaks

The default behaviour of HtmlElement is maximum security. But if you have thousands of HTML tags it could be slow. If your HTML attributes are not from user input, you can disable escaping of HTML attributes to increase performance. You can also disable escaping of text to unleash the beast. ;-) This is simply done by adding the following lines to your module.config.php, but keep security in mind.


return array(
    'sake_htmlelement' => array(
        'view_helper' => array(
            'default' => array(
                'escapeHtmlAttribute' => false,
                'escapeText' => false,
    // other module config stuff