Skip to content

Commit 6a219b0

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Add the versionadded directive Frontend Encore document passing data via serialize twig filter
2 parents b4ee5cb + e976964 commit 6a219b0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

frontend/encore/server-data.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ them later in JavaScript. For example:
88

99
.. code-block:: html+twig
1010

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+
>
1215
<!-- ... -->
1316
</div>
1417

18+
.. versionadded:: 5.3
19+
20+
The ``serialize()`` Twig filter was introduced in Symfony 5.3.
21+
1522
Fetch this in JavaScript:
1623

1724
.. code-block:: javascript
1825
1926
document.addEventListener('DOMContentLoaded', function() {
2027
var userRating = document.querySelector('.js-user-rating');
2128
var isAuthenticated = userRating.dataset.isAuthenticated;
29+
var user = JSON.parse(userRating.dataset.user);
2230
2331
// or with jQuery
2432
//var isAuthenticated = $('.js-user-rating').data('isAuthenticated');

0 commit comments

Comments
 (0)