You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+91Lines changed: 91 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,97 @@ This tag helper would be called for every HTML element that has a `my-attribute`
89
89
90
90
### Manipulating DOM Elements
91
91
92
+
Once your tag helper successfully matches one or multiple HTML elements, the `process` method of your tag helper will be called.
93
+
94
+
Inside of this method, you can manipulate the HTML element.
95
+
96
+
Available features:
97
+
98
+
#### Changing the HTML element tag
99
+
100
+
In this example, we are binding our helper to HTML elements `<my-custom-link href="/"></my-custom-link>`. In the process method, we can then change the tag internally to `a` to render this as a link.
101
+
102
+
```php
103
+
<?php
104
+
105
+
namespace BeyondCode\TagHelper\Helpers;
106
+
107
+
use BeyondCode\TagHelper\Helper;
108
+
use BeyondCode\TagHelper\Html\HtmlElement;
109
+
110
+
class CustomLink extends Helper
111
+
{
112
+
protected $targetElement = 'my-custom-link';
113
+
114
+
public function process(HtmlElement $element)
115
+
{
116
+
$element->setTag('a');
117
+
}
118
+
}
119
+
```
120
+
121
+
#### Manipulating Attributes
122
+
123
+
You can also add, edit or delete HTML element attributes.
124
+
125
+
In this example, we are binding our helper to all link tags that have a custom `route` attribute.
126
+
We then update the `href` attribute of our link, remove the `route` attribute and add a new `title` attribute.
0 commit comments