Skip to content

Commit c30316f

Browse files
committed
merged branch pierredup/hinclude (PR #5993)
This PR was merged into the master branch. Commits ------- 74a8fcf [FrameworkBundle] Added support for default templates per render tag Discussion ---------- [FrameworkBundle] Added support for default templates per render tag This commit allows you to specify default templates per render tag when using hinclude. E.G: The following will use the specific default template for the render: ```` {% render "AcmeDemoBundle:Controller:action" with {}, {"standalone" : "js", "default" : "AcmeDemoBundle:Default:content.html.twig"} %}```` or if you don't want to use a template for the default content but just a string, you can do the following ```` {% render "AcmeDemoBundle:Controller:action" with {}, {"standalone" : "js", "default" : "Loading..."} %}```` Bug fix: no Feature addition: yes Backwards compatibility break: no Fixes the following tickets: #3356 Todo: - Documentation --------------------------------------------------------------------------- by fabpot at 2012-12-14T12:25:40Z Looks good to me. Can you add a note in the CHANGELOG of the component and send a PR on symfony/symfony-docs about this new feature? Thanks. --------------------------------------------------------------------------- by pierredup at 2012-12-14T14:30:00Z @fabpot done, documentation PR symfony/symfony-docs#2021
2 parents 954828f + 29e2eb6 commit c30316f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* A new parameter has been added to the DIC: `router.request_context.base_url`
1111
You can customize it for your functional tests or for generating urls with
1212
the right base url when your are in the cli context.
13+
* Added support for default templates per render tag
1314

1415
2.1.0
1516
-----

HttpKernel.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function render($controller, array $options = array())
105105
'alt' => array(),
106106
'standalone' => false,
107107
'comment' => '',
108+
'default' => null,
108109
), $options);
109110

110111
if (!is_array($options['alt'])) {
@@ -130,8 +131,16 @@ public function render($controller, array $options = array())
130131
$uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false);
131132
$defaultContent = null;
132133

133-
if ($template = $this->container->getParameter('templating.hinclude.default_template')) {
134-
$defaultContent = $this->container->get('templating')->render($template);
134+
$templating = $this->container->get('templating');
135+
136+
if ($options['default']) {
137+
if ($templating->exists($options['default'])) {
138+
$defaultContent = $templating->render($options['default']);
139+
} else {
140+
$defaultContent = $options['default'];
141+
}
142+
} elseif ($template = $this->container->getParameter('templating.hinclude.default_template')) {
143+
$defaultContent = $templating->render($template);
135144
}
136145

137146
return $this->renderHIncludeTag($uri, $defaultContent);
@@ -226,7 +235,7 @@ public function generateInternalUri($controller, array $attributes = array(), ar
226235
/**
227236
* Renders an HInclude tag.
228237
*
229-
* @param string $uri A URI
238+
* @param string $uri A URI
230239
* @param string $defaultContent Default content
231240
*/
232241
public function renderHIncludeTag($uri, $defaultContent = null)

0 commit comments

Comments
 (0)