Skip to content

Commit 1bac4ba

Browse files
committed
added custom tag documentation
1 parent 60b97ac commit 1bac4ba

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,45 @@ h::div(
231231
</div>
232232
```
233233

234+
# Overwriting Normal HTML Tags
235+
Firstly, this library is markup agnostic. That means, whatsoever you call will be considered as a markup. For example,
236+
```php
237+
h::you(
238+
class: 'you-class',
239+
id: 'you-1',
240+
text: 'Hello you'
241+
);
242+
```
243+
will produce an output
244+
```html
245+
<you class="you-class" id="you-1">Hello you</you>
246+
```
247+
248+
The main benefit of this is that you can define any html element to behave the way you want. The main logic under this is the `handle` method which does the actual rendering.
249+
> When redefining the behavior of an element, do not call the element as a function in its own definition, this can result in an infinite recursion.
250+
251+
**Redefining the `<p>` element**
252+
```php
253+
# custom-tags.php
254+
use LeviZwannah\PhpMarkup\Facades\Markup as pm;
255+
256+
pm::component(
257+
name: "p",
258+
render: function($mainArgs, $args){
259+
# add more classes to p
260+
$classes = $args['class'] ?? "";
261+
$classes = "custom-p-class $classes custom-p-class-2";
262+
$args['class'] = $classes;
263+
264+
# you could even put the p in a div by default.
265+
266+
return pm::handle('p', $args);
267+
},
268+
specialArgs: []
269+
);
270+
```
234271

272+
**Whenevery `pm::p(...)` is called, your custom definition will be the default behavior of the p tag**.
235273

236274

237275
# Installation

0 commit comments

Comments
 (0)