File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -8,17 +8,25 @@ them later in JavaScript. For example:
8
8
9
9
.. code-block :: html+twig
10
10
11
- <div class="js-user-rating" data-is-authenticated="{{ app.user ? 'true' : 'false' }}">
11
+ <div class="js-user-rating"
12
+ data-is-authenticated="{{ app.user ? 'true' : 'false' }}"
13
+ data-user="{{ app.user|serialize(format = 'json') }}"
14
+ >
12
15
<!-- ... -->
13
16
</div>
14
17
18
+ .. versionadded :: 5.3
19
+
20
+ The ``serialize() `` Twig filter was introduced in Symfony 5.3.
21
+
15
22
Fetch this in JavaScript:
16
23
17
24
.. code-block :: javascript
18
25
19
26
document .addEventListener (' DOMContentLoaded' , function () {
20
27
var userRating = document .querySelector (' .js-user-rating' );
21
28
var isAuthenticated = userRating .dataset .isAuthenticated ;
29
+ var user = JSON .parse (userRating .dataset .user );
22
30
23
31
// or with jQuery
24
32
// var isAuthenticated = $('.js-user-rating').data('isAuthenticated');
You can’t perform that action at this time.
0 commit comments