https://github.com/attitude/render-tag-php
Render (HTML) tags with proper indenting. It resembles React.createElement( component, props, ...children) API except the children argument.
https://github.com/attitude/render-tag-php
Last synced: 3 months ago
JSON representation
Render (HTML) tags with proper indenting. It resembles React.createElement( component, props, ...children) API except the children argument.
- Host: GitHub
- URL: https://github.com/attitude/render-tag-php
- Owner: attitude
- License: mit
- Created: 2020-10-08T19:04:47.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-27T20:42:08.000Z (over 4 years ago)
- Last Synced: 2025-01-18T02:14:46.766Z (5 months ago)
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Render HTML Tag for PHP
Render (HTML) tags with proper indenting. It resembles React.createElement( component, props, ...children) API except the children argument.
## API
### `function renderTag(string $tag = '', array $props = [])`
- *string* `$htmlTag` – div, span, section, header... name it
- *array* `$props` – Associative array of attributes and attribute values. See [Props](#props) for example.### `function mergeProps(array $oldProps, array $newProps)`
Alias for [array_merge()](https://www.php.net/manual/en/function.array-merge.php).### `function valueWhen(mixed $valueIfTrue, boolean|mixed $condition)`
Ternary-like operator helper, when all you need to pick value if true otherwise passe `null`. Sometimes this is more readable. Pick your choice.### `function defaultValue ($value, $default)`
Returns value or the default when value is not present.When passed 3 params, works as ternary: `function valueWhen(mixed $valueIfTrue, mixed $valueIfFalse, boolean|mixed $condition)`.
## Props
Props (arguments) should be an associative array of attributes and attribute values.
```php
$props = [
"id" => 'single-value',
"class" => [
'multiple',
null, // Empty values are skipped
'values',
],
"children" => 'Text inside',
...
]echo renderTag('p', $props);
```Renders:
```html
Text inside
```