2017 © Pedro Peláez
 

library htattrs

Build html attributes through the ArrayObject API

image

flsouto/htattrs

Build html attributes through the ArrayObject API

  • Sunday, April 2, 2017
  • by flsouto
  • Repository
  • 0 Watchers
  • 1 Stars
  • 86 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

HtAttrs

This package can be used to build html tag attributes through a simple, array-based API., (*1)

Installation

Use composer:, (*2)

composer require flsouto/htattrs

Usage

Building html attributes:, (*3)

<?php

require_once('vendor/autoload.php');

$attrs = new FlSouto\HtAttrs();
$attrs['name'] = 'test';
$attrs['onclick'] = 'alert("Test!")';

echo "<a $attrs>Click me</a>";

The above code will produce:, (*4)

<a name="test" onclick="alert(&quot;Test!&quot;)">Click me</a>

Since the HtAttrs class extends php's native \ArrayObject, you could initialize it with an array:, (*5)

``` <?php, (*6)

require_once('vendor/autoload.php');, (*7)

$attrs = new FlSouto\HtAttrs([ 'name' => 'test', 'onclick' => 'alert("Test!")' ]);, (*8)

echo "Click me";, (*9)


The above code will produce:

Click me, (*10)


## The Especial Style Attribute The style attribute is always an instance of the FlSouto\HtAttrStyle class, which in turn produces a list of inline css properties when outputted:

<?php, (*11)

require_once('vendor/autoload.php');, (*12)

$attrs = new FlSouto\HtAttrs([ 'name' => 'test', 'onclick' => 'alert("Test!")' ]);, (*13)

$attrs['style']['color'] = 'black';, (*14)

// it's also possible to get the object: $style = $attrs['style']; $style['padding'] = '5px';, (*15)

echo "Click me";, (*16)

The above code outputs:

Click me ```, (*17)

The Versions

02/04 2017

dev-master

9999999-dev

Build html attributes through the ArrayObject API

  Sources   Download

by fabio

html

02/04 2017

1.0.2

1.0.2.0

Build html attributes through the ArrayObject API

  Sources   Download

by fabio

html

15/11 2016

1.0.1

1.0.1.0

Build html attributes through the ArrayObject API

  Sources   Download

by fabio

html

24/10 2016

1.0.0

1.0.0.0

Build html attributes through the ArrayObject API

  Sources   Download

by fabio

html