Skip to content

Added escaping tip #6633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,18 @@ a template helper function:
Read this blog post.
</a>

.. tip::

If you are generating the route inside a script tag, you might need to properly escape it for Javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should end the sentence with a colon. And can you please also wrap this paragraph after the first word that crosses the 72nd character?


.. code-block:: javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use javascript+jinja here


<script>
var route = "{{ path('blog_show', {'slug': 'my-blog-post'})|escape('js') }}";
</script>

For more information, see the Twig documentation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should link to the documentation of the escape filter here:

For more information, see the `Twig documentation`_.

You then need to add the following to the bottom of the document too:

.. _`Twig documentation`: http://twig.sensiolabs.org/doc/filters/escape.html


.. index::
single: Routing; Absolute URLs

Expand Down