2017 © Pedro Peláez
 

library html

Html tag generator classes.

image

wscore/html

Html tag generator classes.

  • Tuesday, August 20, 2013
  • by asaokamei
  • Repository
  • 1 Watchers
  • 2 Stars
  • 39 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

WScore.Html

Html tag generation class for PHP., (*1)

Installation

$ composer require wscore/html

Sample Codes

Basic HTML

use WScore\Html\Html class to create an HTML object, as;, (*2)

use WScore\Html\Html;

$html = Html::create('tagName')
            ->set('attribute', 'value')
            ->setContents('content');
echo (string) $html;

should output HTML like,, (*3)

<tagName attribute="value">content</tagName>

You can set, add, remove, reset, attributes., (*4)

There are some magic methods as well., (*5)

$html = Html::a('sample link')       // magic method to create a new tag and contents
            ->href('check.php')    // magic method to set href attribute
            ->target('_blank');

HTML Form

use WScore\Html\Form class to create a HTML form object, as;, (*6)

echo Form::open('check.php');
echo Form::input('checkbox', 'keep', 'alive')->class('form-element');
echo Form::close(); 

should create something like:, (*7)

<form action="check.php" method="post">
<input type="checkbox" name="keep" id="keep" value="alive" class="form-element">
</form>

Some Complex Case

To create a nested html code,, (*8)

echo Html::create('ul')
            ->class('form-list')
            ->setContents(
                Form::input('text', 'name')->placeholder('name here...'),
                Form::input('radio', 'yes', 'here')
            );

should result in following html code., (*9)

<ul class="form-list">
<input type="text" name="name" id="name" placeholder="name here...">
<input type="radio" name="yes" id="yes" value="here">
</ul>

Choices (radio, checkbox, and select)

User Form::choices method to generate choices, such as radio buttons, checkboxes, and drop down selects., (*10)

For radio buttons;, (*11)

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2);

for checkboxes;, (*12)

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2)
    ->multiple();

and for drop-down selects;, (*13)

echo Form::choices('test', [
    'val1' => 'label1', 
    'val2' => 'label2'], 
    'val2)
    ->expand(false);

Demo

To see WScore.Html working in the demo,, (*14)

$ git clone https://github.com/asaokamei/WScore.Html
$ cd WScore.Html
$ composer install
$ cd demo
$ php -S 127.0.0.1:8000

and browse the last URL., (*15)

The Versions

20/08 2013

0.1.x-dev

0.1.9999999.9999999-dev

Html tag generator classes.

  Sources   Download

by Asao Kamei

20/08 2013

dev-master

9999999-dev

Html tag generator classes.

  Sources   Download

by Asao Kamei

20/08 2013

0.1.0

0.1.0.0

Html tag generator classes.

  Sources   Download

by Asao Kamei