Skip to content

Commit 8cbd129

Browse files
kingcrunchweaverryan
authored andcommitted
Added cookbook entry about FrameworkBundle:TemplateController
1 parent 432b8a5 commit 8cbd129

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

cookbook/templating/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Templating
77
global_variables
88
PHP
99
twig_extension
10+
render_without_controller
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)