Download the PHP package wongyip/html-tags without Composer
On this page you can find all versions of the php package wongyip/html-tags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wongyip/html-tags
More information about wongyip/html-tags
Files in wongyip/html-tags
Package html-tags
Short Description HTML Tags Renderer
License MIT
Homepage https://github.com/wongyip/html-tags
Informations about the package html-tags
HTML Tags Renderer
A simple HTML renderer with fluent interface to generate dynamic components. Those generated tags are self-rendered, so it is not necessary to build extra logic into templates to handle them, which helps to reduce the complexity of templates and also make certain components independent of template engines.
Read This First
This package doesn't take cares of security at all, if your application generates HTML from dynamic data, especially user-contributed contents, be very careful to avoid something like XSS attack. You should always employ your own favour of HTML filtering tool, e.g. HTML Purifier.
The World is Dangerous, Always Sanitize Generated HTML.
Installation
Usage
Basic
The above output are not syntax highlighted to properly display the contents escaped by the htmlspecialchars
function.
Various Coding Style
Tags may be rendered in different ways to fit into different scenarios.
Nesting
Contents Collections
Tags extending the TagAbstract
will have a several ContentsCollection
properties, which are empty on instantiate,
and accessible in public scope. You may make use of them to manipulate all the contents of a tag.
TagAbstract::$siblingsBefore
- sibling tags with the same nesting level of the tag, rendered before the tag.TagAbstract::$contentsPrefixed
- inner contents on top of the tag.TagAbstract::$contents
- inner contents of the tag.TagAbstract::$contentsSuffixed
- inner contents at the bottom of the tag.TagAbstract::$siblingsAfter
- sibling tags with the same nesting level of the tag, rendered after the tag.
Extensible Contents
For scenario of tags with conditional inner contents, you may extend the following methods to handle the needs:
TagAbstract::contentsBefore()
, that output aContentsCollection
for render right before the tag's contents.TagAbstract::contentsAfter()
that output aContentsCollection
for render right after the tag's contents.
For example, the build-in Table
tag extended the contentsBefore()
method to insert its
caption
, thead
and tbody
when they're set.
Contents Anatomy, Concluded
- Siblings Before the Tag
- Prefixed Contents
- Extensible Contents (Before)
- Contents
- Extensible Contents (After)
- Suffixed Contents
- Siblings After the Tag
The following example illustrates the above anatomy excepts of the Extensible Contents (Before and After):
Comment
The above output are not syntax highlighted to properly display the contents escaped by the htmlspecialchars
function.
More Examples
- See
Demo::class
for more examples. - Run
php demo/demo.php
for demonstration in CLI.
Limitations
- This is NOT a rendering engine.
<script>
tag is not supported, obviously because of the security concerns.<style>
tag is neither supported ashtmlspecialchars()
might unintentionally break the styles.<!doctype>
tag is not supported also.- Web content accessibility is not addressed, yet.
- Tags are rendered into a single line, if formatted HTML is needed, give HTML Beautify a try.
Always Sanitize Generated HTML.
All versions of html-tags with dependencies
ext-ctype Version *
ext-mbstring Version *