Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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

  • Lorem
  • ipsum
  • ';
    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()`
    * `