Skip to content

Commit 9411fd3

Browse files
committed
tweaks!
1 parent 96db622 commit 9411fd3

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

routing.rst

+4-38
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Later, you'll use it to generate URLs.
134134
.. sidebar:: Routing in Other Formats
135135

136136
The ``@Route`` above each method is called an *annotation*. If you'd rather
137-
configure your routes in Yaml, XML or PHP, that's no problem!
137+
configure your routes in YAML, XML or PHP, that's no problem!
138138

139139
In these formats, the ``_controller`` "defaults" value is a special key that
140140
tells Symfony which controller should be executed when a URL matches this route.
@@ -150,8 +150,8 @@ even the most complex URLs easy.
150150

151151
.. _routing-requirements:
152152

153-
Adding {placeholder} Requirements
154-
---------------------------------
153+
Adding {wildcard} Requirements
154+
------------------------------
155155

156156
Imagine the ``blog_list`` route will contain a paginated list of blog posts, with
157157
URLs like ``/blog/2`` and ``/blog/3`` for pages 2 and 3. If you change the route's
@@ -648,41 +648,7 @@ Generating URLs from a Template
648648
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649649

650650
To generate URLs inside Twig, see the templating chapter: :ref:`book-templating-pages`.
651-
652-
Generating URLs in JavaScript
653-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
654-
655-
If you're in a Twig template, you can use the same ``path`` function to set JavaScript
656-
variables. The ``escape`` function helps escape any non-JavaScript-safe values:
657-
658-
.. configuration-block::
659-
660-
.. code-block:: html+twig
661-
662-
<script>
663-
var route = "{{ path('blog_show', {'slug': 'my-blog-post'})|escape('js') }}";
664-
</script>
665-
666-
.. code-block:: html+php
667-
668-
<script>
669-
var route = "<?php echo $view->escape(
670-
$view['router']->generate('blow_show', array(
671-
'slug' => 'my-blog-post',
672-
)),
673-
'js'
674-
) ?>";
675-
</script>
676-
677-
But if you *actually* need to generate routes in pure JavaScript, consider using
678-
the `FOSJsRoutingBundle`_. It makes the following possible:
679-
680-
.. code-block:: javascript
681-
682-
var url = Routing.generate(
683-
'blog_show',
684-
{'slug': 'my-blog-post'}
685-
);
651+
If you also need to generate URLs in JavaScript, see :doc:`/routing/generate_url_javascript`.
686652

687653
.. index::
688654
single: Routing; Absolute URLs

routing/generate_url_javascript.rst

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
How to Generate Routing URLs in JavaScript
2+
==========================================
3+
4+
If you're in a Twig template, you can use the same ``path`` function to set JavaScript
5+
variables. The ``escape`` function helps escape any non-JavaScript-safe values:
6+
7+
.. configuration-block::
8+
9+
.. code-block:: html+twig
10+
11+
<script>
12+
var route = "{{ path('blog_show', {'slug': 'my-blog-post'})|escape('js') }}";
13+
</script>
14+
15+
.. code-block:: html+php
16+
17+
<script>
18+
var route = "<?php echo $view->escape(
19+
$view['router']->generate('blow_show', array(
20+
'slug' => 'my-blog-post',
21+
)),
22+
'js'
23+
) ?>";
24+
</script>
25+
26+
But if you *actually* need to generate routes in pure JavaScript, consider using
27+
the `FOSJsRoutingBundle`_. It makes the following possible:
28+
29+
.. code-block:: javascript
30+
31+
var url = Routing.generate('blog_show', {
32+
'slug': 'my-blog-post'
33+
});

0 commit comments

Comments
 (0)