Skip to content

Added cookbook entry about FrameworkBundle:TemplateController #2002

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions cookbook/templating/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Templating
global_variables
PHP
twig_extension
render_without_controller
67 changes: 67 additions & 0 deletions cookbook/templating/render_without_controller.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.. index::
single: Templating; Render template without custom controller

How to render a template without a custom controller
====================================================

This guide explains how to render a template within another template and
how to configure a page without a custom controller.

The intention is, that there may be page in your application, that doesn't
need a controller, because there is no action associated with them.

Rendering a template in twig:

.. code-block:: jinja

{% render "FrameworkBundle:Template:template" with {template: 'AcmeBundle::static.html.twig'} %}

Directly routing to a template without custom controller with additional
caching parameters:

.. configuration-block::

.. code-block:: yaml

acme_static:
pattern: /static
defaults:
_controller: FrameworkBundle:Template:template
template: 'AcmeBundle::static.html.twig'
maxAge: 86400
sharedMaxAge: 86400

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="acme_static" pattern="/static">
<default key="_controller">FrameworkBundle:Template:template</default>
<default key="template">AcmeBundle::static.html.twig</default>
<default key="maxAge">86400</default>
<default key="sharedMaxAge">86400</default>
</route>
</routes>

.. code-block:: php

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();
$collection->add('acme_static', new Route('/static', array(
'_controller' => 'FrameworkBundle:Template:template',
'template' => 'Acmebundle::static.html.twig',
'maxAge' => 86400,
'sharedMaxAge' => 86400,
)));

return $collection;

By default no caching headers were set. If you want to disable proxy
caching, but want to keep browser caching enabled, set ``private`` to
``false`` explictly.