Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa6fdee

Browse files
committed
[symfony#2002] Updating the new entry to not include the 2.2-only caching features and proofreading
The caching stuff will be added back on the master branch
1 parent8cbd129 commitfa6fdee

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

‎cookbook/map.rst.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
* :doc:`/cookbook/templating/global_variables`
130130
* :doc:`/cookbook/templating/PHP`
131131
* :doc:`/cookbook/templating/twig_extension`
132+
* :doc:`/cookbook/templating/render_without_controller`
132133

133134
* :doc:`/cookbook/testing/index`
134135

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
..index::
22
single: Templating; Render template without custom controller
33

4-
How to render atemplate without a customcontroller
4+
How to render aTemplate without a customController
55
====================================================
66

7-
This guide explains how to render a template within another template and
8-
how to configure a page without a custom controller.
7+
Usually, when you need to create a page, you need to create a controller
8+
and render a template from within that controller. But if you're rendering
9+
a simple template that doesn't need any data passed into it, you can avoid
10+
creating the controller entirely, by using the built-in ``FrameworkBundle:Template:template``
11+
controller.
912

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:
13+
For example, suppose you want to render a ``AcmeBundle:Static:privacy.html.twig``
14+
template, which doesn't require that any variables are passed to it. You
15+
can do this without creating a controller:
2116

2217
..configuration-block::
2318

2419
..code-block::yaml
2520
26-
acme_static:
27-
pattern:/static
21+
acme_privacy:
22+
pattern:/privacy
2823
defaults:
2924
_controller:FrameworkBundle:Template:template
30-
template:'AcmeBundle::static.html.twig'
31-
maxAge:86400
32-
sharedMaxAge:86400
25+
template:'AcmeBundle:Static:privacy.html.twig'
3326
3427
..code-block::xml
3528
@@ -39,11 +32,9 @@ caching parameters:
3932
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4033
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
4134
42-
<routeid="acme_static"pattern="/static">
35+
<routeid="acme_privacy"pattern="/privacy">
4336
<defaultkey="_controller">FrameworkBundle:Template:template</default>
44-
<defaultkey="template">AcmeBundle::static.html.twig</default>
45-
<defaultkey="maxAge">86400</default>
46-
<defaultkey="sharedMaxAge">86400</default>
37+
<defaultkey="template">AcmeBundle:Static:privacy.html.twig</default>
4738
</route>
4839
</routes>
4940
@@ -53,15 +44,30 @@ caching parameters:
5344
use Symfony\Component\Routing\Route;
5445
5546
$collection = new RouteCollection();
56-
$collection->add('acme_static', new Route('/static', array(
47+
$collection->add('acme_privacy', new Route('/privacy', array(
5748
'_controller' => 'FrameworkBundle:Template:template',
58-
'template' => 'Acmebundle::static.html.twig',
59-
'maxAge' => 86400,
60-
'sharedMaxAge' => 86400,
49+
'template' => 'AcmeBundle:Static:privacy.html.twig',
6150
)));
6251
6352
return $collection;
6453
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.
54+
The ``FrameworkBundle:Template:template`` controller will simply render whatever
55+
template you've passed as the ``template`` default value.
56+
57+
You can of course also use this trick when rendering embedded controllers
58+
from within a template. But since the purpose of rendering a controller from
59+
within a template is typically to prepare some data in a custom controller,
60+
this probably isn't useful, except to easily cache static partials, a feature
61+
which will become available in Symfony 2.2.
62+
63+
..configuration-block::
64+
65+
..code-block::html+jinja
66+
67+
{% render url('acme_privacy') %}
68+
69+
..code-block::html+php
70+
71+
<?php echo $view['actions']->render(
72+
$view['router']->generate('acme_privacy', array(), true)
73+
) ?>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp