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: docs/helpers.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Turbo Laravel has a set of Blade Directives, Components, helper functions, and r
11
11
12
12
## Blade Directives
13
13
14
-
### The `@domid()` Blade Directive
14
+
### The DOM ID Blade Directive
15
15
16
16
Since Turbo relies a lot on DOM IDs, the package offers a helper to generate unique DOM IDs based on your models. You may use the `@domid` Blade Directive in your Blade views like so:
17
17
@@ -33,7 +33,7 @@ Which will generate a `comments_post_123` DOM ID, assuming your Post model has a
33
33
34
34
## Blade Components
35
35
36
-
### The `<x-turbo::frame>` Blade Component
36
+
### The Turbo Frame Blade Component
37
37
38
38
You may also prefer using the `<x-turbo::frame>` Blade component that ships with the package. This way, you don't need to worry about using the `@domid()` helper for your Turbo Frame:
39
39
@@ -53,7 +53,7 @@ To the `:id` prop, you may pass a string, which will be used as-is as the DOM ID
53
53
54
54
Additionally, you may also pass along any prop that is supported by the Turbo Frame custom Element to the `<x-turbo::frame>` Blade component, like `target`, `src`, or `loading`. These are the listed attributes, but any other attribute will also be forwarded to the `<turbo-frame>` tag that will be rendered by the `<x-turbo::frame>` component. For a full list of what's possible to do with Turbo Frames, see the [documentation](https://turbo.hotwired.dev/handbook/frames).
55
55
56
-
### The `<x-turbo::stream>` Blade Component
56
+
### The Turbo Stream Blade Component
57
57
58
58
If you're rendering a Turbo Stream inside a your Blade files, you may use the `<x-turbo::stream>` helper:
59
59
@@ -65,7 +65,7 @@ If you're rendering a Turbo Stream inside a your Blade files, you may use the `<
65
65
66
66
Just like in the Turbo Frames' `:id` prop, the `:target` prop of the Turbo Stream component accepts a string, a model instance, or an array to resolve the DOM ID using the `dom_id()` function.
67
67
68
-
### The `<x-turbo::refresh-method method="morph" />` Blade Component
68
+
### The Refresh Method Blade Component
69
69
70
70
We can configure which update method Turbo should so to update the document:
### The `<x-turbo::refreshes-with>` Blade Component
110
+
### The Refresh Behaviors Blade Component
111
111
112
112
You may configure both the refresh method and scroll behavior using the `<x-turbo::refreshes-with />` component in your main layout's `<head>` tag or on specific pages to configure how Turbo should update the page. Here's an example:
113
113
@@ -122,7 +122,7 @@ This will render two HTML `<meta>` tags:
### The `<x-turbo::exempts-page-from-preview />` Blade Component
139
+
### The Page Preview Exemption Blade Component
140
140
141
141
This component may be added to any page you don't want Turbo to show as a preview on regular navigation visits. No-preview pages will only be used in restoration visits (when you use the browser's back or forward buttons, or when when moving backward in the navigation stack). Example:
142
142
@@ -150,7 +150,7 @@ It will render the HTML `<meta>` tag:
### The `<x-turbo::page-requires-reload />` Blade Component
153
+
### The Page Reload Blade Component
154
154
155
155
This component may be added to any page you want Turbo to reload. This will break out of Turbo Frame navigations. May be used at a login screen, for instance. Example:
156
156
@@ -168,7 +168,7 @@ It will render the HTML `<meta>` tag:
168
168
169
169
The package ships with a set of helper functions. These functions are all namespaced under `HotwiredLaravel\\TurboLaravel\\` but we also add them globally for convenience, so you may use them directly without the `use` statements (this is useful in contexts like Blade views, for instance).
170
170
171
-
### The `dom_id()`
171
+
### The DOM ID Helper Function
172
172
173
173
The mentioned namespaced `dom_id()` helper function may also be used from anywhere in your application, like so:
174
174
@@ -182,7 +182,7 @@ When a new instance of a model is passed to any of these DOM ID helpers, since i
182
182
183
183
These helpers strip out the model's FQCN (see [config/turbo-laravel.php](https://github.com/hotwired-laravel/turbo-laravel/blob/main/config/turbo-laravel.php) if you use an unconventional location for your models).
184
184
185
-
### The `dom_class()`
185
+
### The DOM CSS Class Helper Function
186
186
187
187
The `dom_class()` helper function may be used from anywhere in your application, like so:
Both the `Response::turboStream()` and the `turbo_stream()` function work the same way. The `turbo_stream()` function may be easier to use.
216
216
217
-
### The `turbo_stream_view()`
217
+
### The Turbo Stream View Helper Function
218
218
219
219
You may combo Turbo Streams using the `turbo_stream([])` function passing an array, but you may prefer to create a separate Blade view with all the Turbo Streams, this way you may also use template extensions and everything else Blade offers:
The `request()->wantsTurboStream()` macro added to the request class will check if the request accepts Turbo Stream and return `true` or `false` accordingly.
234
234
235
235
Turbo will add a `Accept: text/vnd.turbo-stream.html, ...` header to the requests. That's how we can detect if the request came from a client using Turbo.
236
236
237
-
### The `request()->wasFromTurboFrame()` macro
237
+
### Detect If Request Was Made From Turbo Frame
238
238
239
239
The `request()->wasFromTurboFrame()` macro added to the request class will check if the request was made from a Turbo Frame. When used with no parameters, it returns `true` if the request has a `Turbo-Frame` header, no matter which specific Turbo Frame.
240
240
@@ -246,16 +246,16 @@ if (request()->wasFromTurboFrame(dom_id($post, 'create_comment'))) {
246
246
}
247
247
```
248
248
249
-
### The `request()->wasFromHotwireNative()` macro
249
+
### Detect If Request Was Made From Hotwire Native Client
250
250
251
251
The `request()->wasFromHotwireNative()` macro added to the request class will check if the request came from a Hotwire Native client and returns `true` or `false` accordingly.
252
252
253
253
Hotwire Native clients are encouraged to override the `User-Agent` header in the WebViews to mention the words `Hotwire Native` on them. This is what this macro uses to detect if it came from a Hotwire Native client.
254
254
255
-
### The `response()->turboStream()` macro
255
+
### Turbo Stream Response Macro
256
256
257
257
The `response()->turboStream()` macro works similarly to the `turbo_stream()` function above. It was only added to the response for convenience.
258
258
259
-
### The `response()->turboStreamView()` macro
259
+
### The Turbo Stream View Response Macro
260
260
261
261
The `response()->turboStreamView()` macro works similarly to the `turbo_stream_view()` function above. It was only added to the response for convenience.
0 commit comments