Giter Club home page Giter Club logo

php-html-generator's Introduction

PHP HTML GENERATOR

Create HTML tags and render them efficiently.

Build status:

  • Master Build Status
  • Dev Build Status

Overview

return HtmlTag::createElement();
// returns an empty HtmlTag Container

return HtmlTag::createElement('a');
// returns an HtmlTag containing a 'a' tag

Why you should use it

  • it always generates valid HTML and XHTML code
  • it makes templates cleaner
  • it's easy to use and fast to execute

Render tags

echo(HtmlTag::createElement('a'));

Simple tags

echo $html->tag('div')
// <div></div>

echo(HtmlTag::createElement('p')->text('some content'));
// <p>some content</p>

Structured tags

echo(HtmlTag::createElement('div')->addElement('a')->text('a text'));
// <div><a>a text</a></div>

$container = HtmlTag::createElement('div');
$container->addElement('p')->text('a text');
$container->addElement('a')->text('a link');
// <div><p>a text</p><a>a link</a></div>

Attributes

Classics attributes (method : 'set')

$tag = $html->tag('a')
	->set('href','./sample.php')
	->set('id','myID')
	->text('my link');
echo( $tag );
// <a href='./sample.php' id='myID'>my link</a>

ID (method : 'id')

$tag = $html->tag('div')
	->id('myID');
echo( $tag );
// <div id='myID'>my link</a>

Class management (method : 'addClass'/'removeClass')

$tag = $html->tag('div')
	->addClass('firstClass')
	->addClass('secondClass')
	->text('my content')
	->removeClass('firstClass');
echo( $tag );
// <div class="secondClass">my content</div>

More

Text and content are generated according to the order of addition
$tag = $html->tag('p')
	->text('a text')
	->addElement('a')
	->text('a link');
// <p>ma text<a>a link</a></p>

To generate content before text, 2 solutions :
$tag = $html->tag('p')
	->addElement('a')
	->text('a link')
	->getParent()
	->text('a text');
or
$tag = $html->tag('p');
$tag->addElement('a')->text('a link');
$tag->text('a text');

// <p><a>a link</a>a text</p>

php-html-generator's People

Contributors

airmanbzh avatar aduh95 avatar mastacontrola avatar justblackbird avatar smetdenis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.