|
| 1 | +.. index:: |
| 2 | + single: Templating; Render template without custom controller |
| 3 | + |
| 4 | +How to render a template without a custom controller |
| 5 | +==================================================== |
| 6 | + |
| 7 | +This guide explains how to render a template within another template and |
| 8 | +how to configure a page without a custom controller. |
| 9 | + |
| 10 | +The intention is, that there may be page in your application, that doesn't |
| 11 | +need a controller, because there is no action associated with them. |
| 12 | + |
| 13 | +Rendering a template in twig: |
| 14 | + |
| 15 | +.. code-block:: jinja |
| 16 | +
|
| 17 | + {% render "FrameworkBundle:Template:template" with {template: 'AcmeBundle::static.html.twig'} %} |
| 18 | +
|
| 19 | +Directly routing to a template without custom controller with additional |
| 20 | +caching parameters: |
| 21 | + |
| 22 | +.. configuration-block:: |
| 23 | + |
| 24 | + .. code-block:: yaml |
| 25 | +
|
| 26 | + acme_static: |
| 27 | + pattern: /static |
| 28 | + defaults: |
| 29 | + _controller: FrameworkBundle:Template:template |
| 30 | + template: 'AcmeBundle::static.html.twig' |
| 31 | + maxAge: 86400 |
| 32 | + sharedMaxAge: 86400 |
| 33 | +
|
| 34 | + .. code-block:: xml |
| 35 | +
|
| 36 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 37 | +
|
| 38 | + <routes xmlns="http://symfony.com/schema/routing" |
| 39 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 40 | + xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> |
| 41 | +
|
| 42 | + <route id="acme_static" pattern="/static"> |
| 43 | + <default key="_controller">FrameworkBundle:Template:template</default> |
| 44 | + <default key="template">AcmeBundle::static.html.twig</default> |
| 45 | + <default key="maxAge">86400</default> |
| 46 | + <default key="sharedMaxAge">86400</default> |
| 47 | + </route> |
| 48 | + </routes> |
| 49 | +
|
| 50 | + .. code-block:: php |
| 51 | +
|
| 52 | + use Symfony\Component\Routing\RouteCollection; |
| 53 | + use Symfony\Component\Routing\Route; |
| 54 | +
|
| 55 | + $collection = new RouteCollection(); |
| 56 | + $collection->add('acme_static', new Route('/static', array( |
| 57 | + '_controller' => 'FrameworkBundle:Template:template', |
| 58 | + 'template' => 'Acmebundle::static.html.twig', |
| 59 | + 'maxAge' => 86400, |
| 60 | + 'sharedMaxAge' => 86400, |
| 61 | + ))); |
| 62 | +
|
| 63 | + return $collection; |
| 64 | +
|
| 65 | +By default no caching headers were set. If you want to disable proxy |
| 66 | +caching, but want to keep browser caching enabled, set ``private`` to |
| 67 | +``false`` explictly. |
0 commit comments