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
Copy file name to clipboardExpand all lines: resources/boost/guidelines/core.blade.php
+36-70Lines changed: 36 additions & 70 deletions
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,36 @@
1
1
## Hotwire/Turbo Core Principles
2
2
- For standard application development, use Hotwire (Turbo + Stimulus)
3
-
- Send HTML over the wire instead of JSON. Keep complexity on the server side.
4
-
- Use Turbo Drive for smooth page transitions without full page reloads.
5
-
- Decompose pages with Turbo Frames for independent sections that update separately.
6
-
- Use Turbo Streams for real-time updates and dynamic content changes.
3
+
- For most interactions, use regular links and form submits (Turbo Drive will make them fast and dynamic)
4
+
- Decompose pages with Turbo Frames for independent sections that update separately
5
+
- Use Turbo Streams for real-time updates and dynamic content changes
7
6
- Leverage Stimulus for progressive JavaScript enhancement when Turbo isn't sufficient (if Stimulus is available)
8
-
- Prefer server-side template rendering and state management over client-side frameworks.
9
-
- Enable "morphing" for seamless page updates that preserve scroll position and focus.
10
-
- Use data attributes for JavaScript hooks
11
-
- For more complex JavaScript dependencies, use Importmap Laravel
7
+
- Prefer server-side template rendering and state management over client-side frameworks and state
8
+
- Use data attributes for JavaScript hooks and CSS styling for as much as possible
12
9
13
-
## Turbo Setup & Base Helpers
10
+
## Base Helpers
14
11
@verbatim
15
12
- Turbo automatically handles page navigation, form submissions, and CSRF protection
16
-
- Enable morphing in your layout (preserves DOM state during page updates): `<x-turbo::refresh-methodmethod="morph" />`
17
-
- Configure scroll behavior in your layout: `<x-turbo::refresh-scrollscroll="preserve" />`
18
-
- Enable both morphing and scroll preservation with a single component: `<x-turbo::refreshes-withmethod="morph"scroll="preserve" />`
19
-
- Generate unique DOM IDs from models: use function `dom_id($model, 'optional_prefix')` or Blade directive `@domid($model, 'optional_prefix')`
20
-
- Generate CSS classes from models: use function `dom_class($model, 'optional_prefix')` or Blade directive `@domclass($model, 'optional_prefix')`
13
+
- You may configure morphing and scroll preservation for a page (or layout) with: `<x-turbo::refreshes-withmethod="morph"scroll="preserve" />`
14
+
- Generate unique DOM IDs from models: use the `dom_id($model, 'optional_prefix')` global function or Blade directive `@domid($model, 'optional_prefix')`
15
+
- Generate CSS classes from models: use the `dom_class($model, 'optional_prefix')` global function or Blade directive `@domclass($model, 'optional_prefix')`
21
16
@endverbatim
22
17
23
18
## Turbo Frames Best Practices
24
-
- Use frames to decompose pages into independent sections that can update without full page reloads:
19
+
- Use frames to decompose pages into independent sections that can update without full page reloads
20
+
- Forms and links inside frames automatically target their containing frame (no configuration needed)
21
+
- You may override the default frame target of a link or form with `[data-turbo-frame]` attribute:
22
+
- Use a frame's DOM ID to target a specific frame
23
+
- Use the value `_top` to break out of frames and navigate the full page
24
+
- The `[:id]` prop accepts models and automatically generates DOM IDs for them
25
+
- The `[:src]` prop accepts a URL to lazy-load from content. Optionally, you may pair it with a `[loading=lazy]` so it only loads when the element is visible in the viewport
26
+
27
+
Example:
25
28
@verbatim
26
29
```blade
27
30
<x-turbo::frame:id="$post">
28
31
<h3>{{$post->title}}</h3>
29
32
<p>{{$post->content}}</p>
30
-
<ahref="{{route('posts.edit', $post) }}">Edit</a>
31
-
</x-turbo::frame>
32
-
```
33
-
@endverbatim
34
-
- Forms and links inside frames automatically target their containing frame (no configuration needed):
- Override default frame targeting with `data-turbo-frame` attribute:
47
-
- Use a frame's DOM ID to target a specific frame
48
-
- Use `_top` to break out of frames and navigate the full page:
49
-
@verbatim
50
-
```blade
51
-
<ahref="{{route('posts.show', $post) }}"data-turbo-frame="_top">View Full Post</a>
52
-
```
53
-
@endverbatim
54
42
55
43
## Turbo Streams for Dynamic Updates
56
-
- Return Turbo Stream responses from controllers to update specific page elements without full page reload:
44
+
45
+
- You may return Turbo Streams from controllers after form submissions to update specific page elements (always check if the request accepts Turbo Streams for resilience)
0 commit comments