Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ui-awesome/html-helper
UI Awesome HTML Helper Code Generator for PHP.
https://github.com/ui-awesome/html-helper
List: html-helper
html-helper php ui-awesome
Last synced: about 2 months ago
JSON representation
UI Awesome HTML Helper Code Generator for PHP.
- Host: GitHub
- URL: https://github.com/ui-awesome/html-helper
- Owner: ui-awesome
- License: mit
- Created: 2024-03-05T08:47:36.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-30T16:15:43.000Z (9 months ago)
- Last Synced: 2024-10-05T06:44:10.821Z (3 months ago)
- Topics: html-helper, php, ui-awesome
- Language: PHP
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
UI Awesome HTML Helpers Code Generator for PHP.
HTML Helper is a PHP library that simplifies the creation of HTML elements. It provides a set of classes to generate
HTML attributes, encode content, sanitize HTML content, and more.## Installation
The preferred way to install this extension is through [composer](https://getcomposer.org/download/).
Either run
```shell
composer require --prefer-dist ui-awesome/html-helper:^0.2
```or add
```json
"ui-awesome/html-helper": "^0.2"
```to the require section of your `composer.json` file.
## Usage
### Add CSS classes
The `CssClasses::class` helper can be used to add CSS classes to an HTML element.
The method accepts three parameters:
- `attributes:` (array): The HTML attributes of the element.
- `classes:` (array|string): The CSS classes to add.
- `overwrite:` (bool): Whether to overwrite the `class` attribute or not. For default, it is `false`.```php
attributes, ['btn', 'btn-primary', 'btn-lg']);
```Overwriting the `class` attribute:
```php
'btn'];$classes = CssClasses::add($this->attributes, ['btn-primary', 'btn-lg'], true);
```### Convert regular expression to pattern
The `Utils::class` helper can be used to normalize a regular expression.
The method accepts one parameter:
- `regexp:` (string): The pattern to normalize.
- `delimiter:` (string): The delimiter to use. For default, it is `null`.```php
alert("Hello, World!")');
```### Encode value
The `Encode::class` helper can be used to encode HTML value.
The method accepts tree parameters:
- `value:` (string): The value to encode.
- `doubleEncode:` (bool): Whether to double encode the value or not. For default, it is `true`.
- `charset:` (string): The charset to use. For default, it is `UTF-8`.```php
alert("Hello, World!")');
```### Get short class name
The `Utils::class` helper can be used to get the short class name.
The method accepts one parameter:
- `class:` (string): The class name to get the short name.
- `suffix:` (string): Whether to append the `::class` suffix to the class name.
For default, it is `true`. If it is `false`, the method will return the short name without the `::class` suffix.
- `lowercase:` (bool): Whether to convert the class name to lowercase or not.
For default, it is `false`.```php
alert("Hello, World!")');
```### Render HTML attributes
The `Attributes::class` helper can be used to `render` HTML attributes in a programmatic way.
```php
'btn btn-primary',
'id' => 'submit-button',
'disabled' => true,
]
);
```### Render HMTL class attribute
The `CssClass::class` helper can be used to render the `class` attribute.
The method accepts one parameter:
- `class:` (string): The class to render.
- `baseClass:` (string): The base class to use.
- `inList:` (array): The list of classes to validate.```php
'prefix',
'{{tag}}' => 'content',
'{{suffix}}' => 'suffix',
];$content = Template::render($template, $tokenValues);
```> `\n` is a new line character, and it is used to separate the tokens in the template.
### Validate value in list
The `Validator::class` helper can be used to validate a value in a list.
The method accepts tree parameters:
- `value:` (mixed): The value to validate.
- `exceptionMessage:` (string): The exception message to throw if the value is not in the list.
- `list:` (...string): The list to validate the value.```php