Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jogemu/ob_html
Seamlessly generate HTML with PHP functions. Use named arguments to set attributes, neatly nest tags and allow HTML forms to update PHP variables.
https://github.com/jogemu/ob_html
html-form html-metadata keyword-arguments named-arguments nested-tags output-buffering passing-by-reference php
Last synced: 9 days ago
JSON representation
Seamlessly generate HTML with PHP functions. Use named arguments to set attributes, neatly nest tags and allow HTML forms to update PHP variables.
- Host: GitHub
- URL: https://github.com/jogemu/ob_html
- Owner: jogemu
- License: unlicense
- Created: 2024-02-29T02:06:29.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-29T01:14:46.000Z (8 months ago)
- Last Synced: 2024-04-29T02:30:38.687Z (8 months ago)
- Topics: html-form, html-metadata, keyword-arguments, named-arguments, nested-tags, output-buffering, passing-by-reference, php
- Language: PHP
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ob_html.php
Seamlessly generate HTML with PHP functions. Use named arguments to set attributes, neatly nest tags and allow HTML forms to update PHP variables.## Quick start
Echo shows the expected output of the previous call.```php
Lorem ipsum';
```Instead of a string, an array can be provided, which is normally concatenated. Some exceptions apply, such as lists, where each entry is placed in its own child element. A more detailed description and further exceptions can be found [here](#special-array-interpretations).
```php
dl(['Lorem'=>'ipsum', 'dolor'=>'sit']);
echo '
- Lorem
- ipsum
- dolor
- sit
```
Provide a function to nest tags without the need to pre-generate content. The PHP interpretation can be exited and re-entered as usual without having to worry about the output buffer. Variables from the parent scope can be made accessible with `function() use (...) {}` or [arrow functions](https://www.php.net/manual/en/functions.arrow.php).
```php
Lorem ipsum
`. Inputs that are `readonly` or `disabled` do not overwrite their variables. The optional parameter `ob_action` may provide a function that is called on form submission.```php
name, name: 'name');
// echo 'John DoeName';
input('Age', $user->age, type: 'number', name: 'age');
// echo 'Age';
button('Submit', type:'submit', name: 'submit', ob_action: fn() => $user->save());
// echo 'Submit';
}, method: 'post');
```
Ultimately, the essential HTML elements are still missing. The native PHP function `ob_start()` should be executed before the first output. At the end, `ob_html()` reads the body from the output buffer, closes it and adds important metadata to the head.
```php
'de.php'],
// other links
links: [
['rel'=>'icon', 'href'=>'favicon.svg']
]
);
```
## Functions
A list of supported functions should not be necessary by design. Assuming familiarity with [HTML elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Element), simply use the functions of the respective name.
### Intentionally excluded
* Essentials and metadata (generated via `ob_html()`)
* ``, ``, ``, ``
* ``, ``, ``, ``
* Items and captions (generated via permitted parent)
* `
* ``, ``
* ``, ``, ``, ``
* ``, ``, ``, ``, ``, `` ``, ``
* ``, ``, ``
* Conflicts with native PHP functions or reserved keywords
* `` => `intro()`
* `` => `variable()`
* `