8000 Update formats.rst by ibronit · Pull Request #7128 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Update formats.rst #7128

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 5 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update formats.rst
  • Loading branch information
ibronit authored Nov 9, 2016
commit 24190e48208fd8ad581e2f0fee4ec3aad28b1f80
24 changes: 15 additions & 9 deletions templating/formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ isn't actually rendered differently based on its format.
In many cases, you may want to allow a single controller to render multiple
different formats based on the "request format". For that reason, a common
pattern is to do the following::
/**
* @Route("/{_format}", name="article_show", defaults={"_format": "html"}, requirements={"_format": "html|pdf"}
*/
public function indexAction(Request $request)
{
$format = $request->getRequestFormat();

return $this->render('article/index.'.$format.'.twig');
}
.. configuration-block::

.. code-block:: php-annotations

/**
* @Route("/{_format}", name="article_show", defaults={"_format": "html"}, requirements={"_format": "html|pdf"}
*/
public function indexAction(Request $request)
{
$format = $request->getRequestFormat();

return $this->render('article/index.'.$format.'.twig');
}


The ``getRequestFormat`` on the ``Request`` object defaults to ``html``,
but can return any other format based on the format requested by the user.
Expand All @@ -41,7 +47,7 @@ be configured so that ``/contact`` sets the request format to ``html`` while
To create links that include the format parameter, include a ``_format``
key in the parameter hash:

.. configuration-block::
.. configuration-block::

.. code-block:: html+twig

Expand Down
0