`)
20 |
21 | ## 1.0.1 - 2017-03-13
22 |
23 | - Fixed: Allow `0` as an attribute value
24 |
25 | ## 1.0.0 - 2016-03-11
26 |
27 | - First release
28 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | Copyright (c) Spatie bvba
4 |
5 | > Permission is hereby granted, free of charge, to any person obtaining a copy
6 | > of this software and associated documentation files (the "Software"), to deal
7 | > in the Software without restriction, including without limitation the rights
8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | > copies of the Software, and to permit persons to whom the Software is
10 | > furnished to do so, subject to the following conditions:
11 | >
12 | > The above copyright notice and this permission notice shall be included in
13 | > all copies or substantial portions of the Software.
14 | >
15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | > THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [](https://supportukrainenow.org)
3 |
4 | # HtmlElement
5 |
6 | [](https://packagist.org/packages/spatie/html-element)
7 | [](https://github.com/spatie/html-element/actions/workflows/run-tests.yml)
8 | [](https://github.com/spatie/html-element/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster)
9 | [](https://packagist.org/packages/spatie/html-element)
10 |
11 | HtmlElement is a library to make dynamic HTML rendering more managable. The syntax is based on [Hyperscript](https://github.com/dominictarr/hyperscript), and adds some [Emmet](http://emmet.io/)-style syntactic sugar too.
12 |
13 | Elements are rendered using the static `HtmlElement::render` method (which I recommend wrapping in a plain function for readability).
14 |
15 | ```php
16 | el('div.container > div.row > div.col-md-6',
17 | el('a', ['href' => '#'], 'Hello world!')
18 | );
19 | ```
20 | ```html
21 |
28 | ```
29 |
30 | ## Support us
31 |
32 | [](https://spatie.be/github-ad-click/html-element)
33 |
34 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
35 |
36 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
37 |
38 | ## Postcardware
39 |
40 | You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
41 |
42 | Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
43 |
44 | The best postcards will get published on the open source page on our website.
45 |
46 | ## Usage
47 |
48 | I recommend adding an `el` function to your application to improve readability over the static method.
49 |
50 | ```php
51 | function el(string $tag, $attributes = null, $content = null) : string
52 | {
53 | return \Spatie\HtmlElement\HtmlElement::render($tag, $attributes, $content);
54 | }
55 | ```
56 |
57 | ## Examples
58 |
59 | An empty tag:
60 |
61 | ```php
62 | el('div');
63 | ```
64 | ```html
65 |
66 | ```
67 |
68 | A plain tag with text contents:
69 |
70 | ```php
71 | el('p', 'Hello world!');
72 | ```
73 | ```html
74 |
Hello world!
75 | ```
76 |
77 | A tag with an attribute:
78 |
79 | ```php
80 | el('p', ['style' => 'color: red;'], 'Hello world!');
81 | ```
82 | ```html
83 |
Hello world!
84 | ```
85 |
86 | A tag with an ID set emmet-style:
87 |
88 | ```php
89 | el('p#introduction', 'Hello world!');
90 | ```
91 | ```html
92 |
Hello world!
93 | ```
94 |
95 | A tag with an emmet-style ID and class:
96 |
97 | ```php
98 | el('p#introduction.red', 'Hello world!');
99 | ```
100 | ```html
101 |
Hello world!
102 | ```
103 |
104 | A tag with emmet-style attributes:
105 |
106 | ```php
107 | el('a[href=#][title=Back to top]', 'Back to top');
108 | ```
109 | ```html
110 | Back to top
111 | ```
112 |
113 | A more complex emmet-style abbreviation:
114 |
115 | ```php
116 | el('div.container > div.row > div.col-md-6', 'Hello world!');
117 | ```
118 | ```html
119 |
224 | ```
225 |
226 | ---
227 |
228 | #### `el(string $tag, array $attributes, string|array $contents) : string`
229 |
230 | When three arguments are passed, the first will be the tag name, the second an array of attributes, and the third a string or an array of contents.
231 |
232 | ```php
233 | el('div', ['class' => 'container'],
234 | el('nav', ['aria-role' => 'navigation'], '...')
235 | );
236 | ```
237 | ```html
238 |