Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Set of php classes for HTML generation
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
nbproject
src
tests
.gitignore
.travis.yml
LICENSE
README
README.md
phpunit.xml

README.md

yuki-html project status

Build Status

Efficient way to create and modify HTML tags.

Why you should use it

Sometimes you need to return html tag from class, and be able to modify it later:

<?php

    class myImage{
        public static function getHtml(){
            return '<img src="myimage.png" />';
        }
    }
    $img = myImage::getHtml();
    // I wanna add alt and style attributes before output, but how I can?
    echo $img;

So, How?

<?php

    use yuki\html\tag;
    class myImage{
        public static function getHtml(){
            return tag::create('img', array('src' => 'myimage.png'));
        }
    }
    $img = myImage::getHtml();

Now you can do what you want:

<?php

    $img['alt'] = 'My Image!';
    $img['style'] = "border: none;";
    echo $img; // <img src="myimage.png" alt="My Image!" style="border: none;" />

You even able to get attributes

<?php

    echo $img['src']; // myimage.png

To remove attributes

<?php

    unset($img['style']);
    echo $img; // <img src="myimage.png" alt="My Image!" />

To wrap

<?php

    use yuki\html\tag;
    $a = tag::create('a', array('href'=>'/'));
    $a->appendChild($img);
    echo $a; // <a href="/"><img src="myimage.png" alt="My Image!" /></a>

To set text, it will be escaped!

<?php

    $a->setText('click here >>');
    echo $a; // <a href="/">click here &gt;&gt;</a>

Usage

<?php

    use yuki\html\tag;
    $head = tag::create('head');
    $head->appendChild(
            tag::create('title')->setText('Page Title')
        );
    $head->appendChild(
            tag::create('meta', array(
                'name'=>'description', 
                'contents' => 'Page Description'
            )
        );
    $head['lang'] = 'en';
    echo $head; // Will output generated html code.

About

Requirements

  • Any flavor of PHP 5.3 should do
  • [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)

Submitting bugs and feature requests

Bugs and feature request are tracked on Github

Author

olamedia - olamedia@gmail.com
See also the list of contributors which participated in this project.

License

yuki-html is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

This library is inspired by symfony (TagHelper), kohana (HTML) and other frameworks

Something went wrong with that request. Please try again.