Download the PHP package nabeghe/nohtml without Composer
On this page you can find all versions of the php package nabeghe/nohtml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nohtml
NoHtml for PHP
Say no to HTML — write views in PHP with a clean, simple DSL.
There are many PHP-based DSLs for HTML out there but NoHTML takes a different route in both behavior and structure.
At its core, there's a class where each method corresponds to an HTML element.
These methods can be used in both static and instance contexts.
Each method accepts a variadic list of arguments representing the element’s children.
The return value of every method is an instance of the Nabeghe\NoHtml\Nodes\Element
class,
whose methods map to the element's attributes, following a Fluent Builder pattern.
🫡 Usage
🚀 Installation
You can install the package via composer:
Example
In the example below, the NoHtml class is made available via an alias named N
.
You can also access the shared instance using the nohtml() function;
however, the below code proceeds in a static manner.
In this code, an HTML element is created right from the start, and then the rest of the page is built around it.
You can define a child element or an attribute value as a callable, so the actual value can be retrieved at the appropriate time.
Children can be plain strings or anything else — they will be converted to strings.
If they are plain strings, they will be escaped, unless the Nabeghe\NoHtml\Nodes\Unescapable
class is used.
Also, a callback defined for children can return a string, an element, or a list of elements.
If it returns a string, that string will not be escaped.
As for attributes, a callback can return the value of the attribute. If the value is null, that attribute won’t be set at all. So, if you want an empty value, use an empty string — null means the attribute doesn't exist. Also, if an attribute is set to true or false, no value will be assigned — true simply means the attribute will be present, and false means it won't be there.
Notice: Setting children for elements like <img>
or <br>
has no effect.
Callbacks
The class related to the callbacks used in the example above:
📖 License
Copyright (c) 2025 https://elatel.ir
Licensed under the MIT license, see LICENSE.md for details.