Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit e95ad8c

Browse files
committed
wip
1 parent ec8db35 commit e95ad8c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,37 @@ class CustomLink extends Helper
180180
}
181181
```
182182

183+
### Passing variables to your tag helpers
184+
185+
If you want to pass view data / global method results into your tag helpers, you can use a colon as a prefix for your attribute data.
186+
Everything inside these colons will be evaluated by PHP and the result is available to your tag helper:
187+
188+
```html
189+
<div :view-data="$myViewVariable"></div>
190+
```
191+
192+
You can then access this data, using the `getAttribute` method inside your helper:
193+
194+
```php
195+
<?php
196+
197+
namespace BeyondCode\TagHelper\Helpers;
198+
199+
use BeyondCode\TagHelper\Helper;
200+
use BeyondCode\TagHelper\Html\HtmlElement;
201+
202+
class CustomLink extends Helper
203+
{
204+
protected $targetAttribute = 'view-data';
205+
protected $targetElement = 'div';
206+
207+
public function process(HtmlElement $element)
208+
{
209+
$element->getAttribute('view-data');
210+
}
211+
}
212+
```
213+
183214
## Built-In Helpers
184215

185216

0 commit comments

Comments
 (0)