Skip to content

Commit 92a1307

Browse files
committed
#15502 Make template shortcuts be usable without Templating component
1 parent f3bfc19 commit 92a1307

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ protected function denyAccessUnlessGranted($attributes, $object = null, $message
159159
*/
160160
public function renderView($view, array $parameters = array())
161161
{
162-
return $this->container->get('templating')->render($view, $parameters);
162+
if ($this->container->has('templating')) {
163+
return $this->container->get('templating')->render($view, $parameters);
164+
}
165+
166+
return $this->container->get('twig')->render($view, $parameters);
163167
}
164168

165169
/**
@@ -173,7 +177,17 @@ public function renderView($view, array $parameters = array())
173177
*/
174178
public function render($view, array $parameters = array(), Response $response = null)
175179
{
176-
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
180+
if ($this->container->has('templating')) {
181+
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
182+
}
183+
184+
if (null === $response) {
185+
$response = new Response();
186+
}
187+
188+
$response->setContent($this->container->get('twig')->render($view, $parameters));
189+
190+
return $response;
177191
}
178192

179193
/**
@@ -187,11 +201,19 @@ public function render($view, array $parameters = array(), Response $response =
187201
*/
188202
public function stream($view, array $parameters = array(), StreamedResponse $response = null)
189203
{
190-
$templating = $this->container->get('templating');
191-
192-
$callback = function () use ($templating, $view, $parameters) {
193-
$templating->stream($view, $parameters);
194-
};
204+
if ($this->container->has('templating')) {
205+
$templating = $this->container->get('templating');
206+
207+
$callback = function () use ($templating, $view, $parameters) {
208+
$templating->stream($view, $parameters);
209+
};
210+
} else {
211+
$twig = $this->container->get('twig');
212+
213+
$callback = function () use ($twig, $view, $parameters) {
214+
$twig->loadTemplate($view)->display($parameters);
215+
};
216+
}
195217

196218
if (null === $response) {
197219
return new StreamedResponse($callback);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy