Skip to content

Commit 4388fe2

Browse files
[9.x] Add Fragment Helpers (#8507)
* [9.x] Add Fragment Helpers Docs for PR: laravel/framework#44774 * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 538b507 commit 4388fe2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

blade.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,26 @@ Then, when rendering the view that utilizes this template, you may invoke the `f
17221722
return view('dashboard', ['users' => $users])->fragment('user-list');
17231723
```
17241724

1725+
The `fragmentIf` method allows you to conditionally return a fragment of a view based on a given condition. Otherwise, the entire view will be returned:
1726+
1727+
```php
1728+
return view('dashboard', ['users' => $users])
1729+
->fragmentIf($request->hasHeader('HX-Request'), 'user-list');
1730+
```
1731+
1732+
The `fragments` and `fragmentsIf` methods allow you to return multiple view fragments in the response. The fragments will be concatenated together:
1733+
1734+
```php
1735+
view('dashboard', ['users' => $users])
1736+
->fragments(['user-list', 'comment-list']);
1737+
1738+
view('dashboard', ['users' => $users])
1739+
->fragmentsIf(
1740+
$request->hasHeader('HX-Request'),
1741+
['user-list', 'comment-list']
1742+
);
1743+
```
1744+
17251745
<a name="extending-blade"></a>
17261746
## Extending Blade
17271747

0 commit comments

Comments
 (0)