Skip to content

Commit fcb6dce

Browse files
committed
minor #21581 Correct escape type for HTML attribute example (ChrisDBrown)
This PR was merged into the 6.4 branch. Discussion ---------- Correct escape type for HTML attribute example From the [Twig documentation](https://twig.symfony.com/doc/3.x/filters/escape.html) the different html escapes are (emphasis mine): - `html`: escapes a string for the HTML body context, or for **HTML attributes values inside quotes**. - `html_attr`: escapes a string when used as an HTML attribute name, and also when used as the value of an **HTML attribute without quotes** (e.g. `data-attribute={{ some_value }}`). The example code here is inside quotes: ``` <div data-user-profile="{{ app.user ? app.user.profileData|json_encode|e('html') }}"> <!-- ... --> </div> ``` so it seems better to recommend `html` as the escape strategy. It'd perhaps be better still to highlight this difference in the Symfony docs? Commits ------- b82557d [Frontend] Correct escape type for HTML attribute example
2 parents ceab14b + b82557d commit fcb6dce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

frontend/server-data.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Fetch this in JavaScript:
3838
const user = JSON.parse(userRating.dataset.user);
3939
4040
There is no size limit for the value of the ``data-*`` attributes, so you can
41-
store any content. In Twig, use the ``html_attr`` escaping strategy to avoid messing
41+
store any content. In Twig, use the ``html`` escaping strategy to avoid messing
4242
with HTML attributes. For example, if your ``User`` object has some ``getProfileData()``
4343
method that returns an array, you could do the following:
4444

4545
.. code-block:: html+twig
4646

47-
<div data-user-profile="{{ app.user ? app.user.profileData|json_encode|e('html_attr') }}">
47+
<div data-user-profile="{{ app.user ? app.user.profileData|json_encode|e('html') }}">
4848
<!-- ... -->
4949
</div>
5050

0 commit comments

Comments
 (0)