Download the PHP package arekx/html-processor without Composer
On this page you can find all versions of the php package arekx/html-processor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package html-processor
html-processor
PHP html processor using arrays
Why
Combining html tags is hard. Standard string concatenation just doesn't work, it's hard to sanitize the input and it just looks ugly. This approach uses arrays to fully create a structure which nicely translates to HTML. But what about template engines like Blade, Mustache, etc?
This was not supposed to replace them, even though it fully could. This was intended so that it can be used in programmatic places where you need to create tags dynamically like recursive menu generators, but do not want to use template engines. Examples for these are widgets which output html or in other places of the code where you would need to output programmatically.
So this:
Translates nicely into:
Usage
Self closing tags
Conditional rendering
You can conditionally render elements or text in arrays. If something is not to be rendered you can pass false
and that part of the rendering will be skipped.
Using callbacks
You can also use callbacks in elements to handle conditional rendering. render($template, $config = [])
function accepts
additional optional parameter for configuration which will be passed to all callbacks used in the template array.
Attributes conditional rendering
If you pass true
to an attribute you will just render that attribute without a value:
NOTE: All attribute values rendered are encoded using htmlspecialchars
.
If you pass false
as a value to any attribute that attribute wont be rendered:
Value for attribute can also be a callback:
Special attributes
If you look closely class="class1 class2"
in above example, it is rendered using 'class' => ['class1', 'class2']
. There are special
renderers for few fields like class
and style
which allows non-string values which can be parsed.
class
attribute allows an array which will be joined with all false
values removed. It also allows for a class value to be a callable.
style
attribute allows for ['property' => 'value']
which will render to property: value
. Value can also be a callable which will get
executed to return property value. If a property value is false
it will be skipped.
Json attributes
You can encode arrays as json in attributes:
Testing
- To run tests run
composer test
. - To generate coverage report run
composer coverage
All versions of html-processor with dependencies
ext-json Version *
ext-mbstring Version *