Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/tei187/php-html-builder

Generates HTML elements (Bootstrap and OpenGraph implementation included).
https://github.com/tei187/php-html-builder

css html html-generator opengraph php-html php74 twitter

Last synced: about 2 months ago
JSON representation

Generates HTML elements (Bootstrap and OpenGraph implementation included).

Awesome Lists containing this project

README

        

# **PHP-TO-HTML package**

## **About**
---
Scripts meant to help out with organizing HTML tag building through PHP, for a rather specific one case but makes sense enough to try out, if you really don't want/need Twig :D

### **Features:**
* **Basic HTML** builder (content, forms, all the parts of HEAD you tend to google for),
* **Bootstrap** equivalent builder,
* **Constants** for Charset, Doctype and Vocabularies,
* **OpenGraph** handling: namespaces, default types, Twitter.


## **Installation**
---
### **Composer**
```shell
composer require tei187/php-html-builder
```


## **Examples**
---
### **Basic HTML**
#### *Input:*
```php
use tei187\HTMLBuilder\Constants\Charset;
use tei187\HTMLBuilder\HTML;
use tei187\HTMLBuilder\Head;
use tei187\HTMLBuilder\OpenGraph;
use tei187\HTMLBuilder\OpenGraph\Prefixes;

echo
HTML::Doctype() .
HTML::Html( [ 'prefix' => Prefixes::og, 'lang' => "en-US" ],
HTML::Head(
Head::Charset( Charset::UTF8 ) .
Head::Title("Testing page") .
OpenGraph::Type('website') .
OpenGraph::Url('localhost') .
OpenGraph::SiteName("Testing page") .
OpenGraph::Description("Just a testing page for HTML builder based on PHP") .
Head::StyleSheet("/assets/css/style.min.css")
) .
HTML::Body( [ 'class' => "main" ],
HTML::Heading( 1, [ 'class' => 'text-red' ], "Hello World!" ) .
HTML::Paragraph( [], "Paragraph example" )
)
);
```
#### *Output:*
```html



Testing page







Hello World!


Paragraph example


```
---

### **Bootstrap**
#### *Input:*
```php
use tei187\HTMLBuilder\HTML;
use tei187\HTMLBuilder\Head;
use tei187\HTMLBuilders\Bootstrap;

echo
HTML::Doctype() .
HTML::Html([],
HTML::Head(
Head::Charset() .
Head::Viewport() .
Head::Title("Bootstrap Example") .
Head::StyleSheet(
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
null,
[
'integrity' => "sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65",
'crossorigin' => "anonymous",
]
)
) .
HTML::Body([],
Bootstrap::Container([],
HTML::Heading(1, [], "Heading") .
Bootstrap::Row([],
Bootstrap::Col(['class' => 'col-12 col-md-6'],
HTML::Image(['alt' => 'Image alternative text'], "/assets/img/image.jpg") .
HTML::Paragraph([], "Paragraph")
)
)
) .
HTML::Script(
[
'src' => "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
'integrity' => "sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4",
'crossorigin' => "anonymous",
]
)
)
);
```
#### *Output:*
```html




Bootstrap Example




Heading




Image alternative text

Paragraph






```

## **Requires**
---
- **UtilitiesPHP** : *tei187/utilities-php* ([GitHub](https://github.com/tei187/UtilitiesPHP) | [Packagist](https://packagist.org/packages/tei187/utilities-php))


## **Author**
---
- [tei187](https://github.com/tei187)