Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit b63e60f

Browse files
committed
Merging develop to master in preparation for 1.3.0 release
2 parents dc35d75 + 9957a3e commit b63e60f

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
.gitignore export-ignore
55
.travis.yml export-ignore
66
phpcs.xml export-ignore
7+
.docheader export-ignore
8+
CONDUCT.md export-ignore
9+
CONTRIBUTING.md export-ignore
710
phpunit.xml.dist export-ignore

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,40 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 1.3.0 - TBD
6+
7+
### Added
8+
9+
- [#23](https://github.com/zendframework/zend-expressive-zendviewrenderer/pull/23)
10+
adds the ability to disable layouts either globally or when rendering. Disable
11+
globally by setting the default `layout` parameter to boolean `false`:
12+
13+
```php
14+
$renderer->addDefaultParam(TemplateRendererInterface::TEMPLATE_ALL, 'layout', false);
15+
```
16+
17+
Or do so when rendering, by passing the template variable `layout` with a
18+
boolean `false` value:
19+
20+
```php
21+
$renderer->render($templateName, [
22+
'layout' => false,
23+
// other template variables
24+
]);
25+
```
26+
27+
### Deprecated
28+
29+
- Nothing.
30+
31+
### Removed
32+
33+
- Nothing.
34+
35+
### Fixed
36+
37+
- Nothing.
38+
539
## 1.2.2 - TBD
640

741
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ To use view helpers, the `ZendViewRendererFactory`:
3434

3535
## Documentation
3636

37-
See the Expressive [ZF View documentation](https://docs.zendframework.com/zend-expressive/features/template/zend-view/).
37+
Browse online at https://docs.zendframework.com/zend-expressive/features/template/zend-view/.

src/ZendViewRenderer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ public function render($name, $params = [])
125125
? $this->mergeViewModel($name, $params)
126126
: $this->createModel($name, $params);
127127

128-
$viewModel = $this->prepareLayout($viewModel);
128+
$useLayout = false !== $viewModel->getVariable('layout', null);
129+
if ($useLayout) {
130+
$viewModel = $this->prepareLayout($viewModel);
131+
}
129132

130133
return $this->renderModel($viewModel, $this->renderer);
131134
}
@@ -321,16 +324,16 @@ private function mergeViewModel($name, ModelInterface $model)
321324
*/
322325
private function prepareLayout(ModelInterface $viewModel)
323326
{
324-
$layout = $this->layout ? clone $this->layout : null;
325-
326-
$providedLayout = $viewModel->getVariable('layout', false);
327+
$providedLayout = $viewModel->getVariable('layout', null);
327328
if (is_string($providedLayout) && ! empty($providedLayout)) {
328329
$layout = new ViewModel();
329330
$layout->setTemplate($providedLayout);
330331
$viewModel->setVariable('layout', null);
331332
} elseif ($providedLayout instanceof ModelInterface) {
332333
$layout = $providedLayout;
333334
$viewModel->setVariable('layout', null);
335+
} else {
336+
$layout = $this->layout ? clone $this->layout : null;
334337
}
335338

336339
if ($layout) {

test/ZendViewRendererTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPUnit\Framework\TestCase;
1212
use Zend\Expressive\Template\Exception\InvalidArgumentException;
1313
use Zend\Expressive\Template\TemplatePath;
14+
use Zend\Expressive\Template\TemplateRendererInterface;
1415
use Zend\Expressive\ZendView\ZendViewRenderer;
1516
use Zend\View\Model\ViewModel;
1617
use Zend\View\Renderer\PhpRenderer;
@@ -279,6 +280,51 @@ public function testCanPassViewModelForLayoutParameterWhenRendering()
279280
$this->assertContains('<title>ALTERNATE LAYOUT PAGE</title>', $result);
280281
}
281282

283+
/**
284+
* @group layout
285+
*/
286+
public function testDisableLayoutOnRender()
287+
{
288+
$layout = new ViewModel();
289+
$layout->setTemplate('zendview-layout');
290+
291+
$renderer = new ZendViewRenderer(null, $layout);
292+
$renderer->addPath(__DIR__ . '/TestAsset');
293+
294+
$name = 'zendview';
295+
$rendered = $renderer->render('zendview', [
296+
'layout' => false,
297+
'name' => $name,
298+
]);
299+
300+
$expected = file_get_contents(__DIR__ . '/TestAsset/zendview.phtml');
301+
$expected = str_replace('<?php echo $name ?>', $name, $expected);
302+
303+
$this->assertEquals($rendered, $expected);
304+
}
305+
306+
/**
307+
* @group layout
308+
*/
309+
public function testDisableLayoutViaDefaultParameter()
310+
{
311+
$layout = new ViewModel();
312+
$layout->setTemplate('zendview-layout');
313+
314+
$renderer = new ZendViewRenderer(null, $layout);
315+
$renderer->addPath(__DIR__ . '/TestAsset');
316+
$renderer->addDefaultParam(TemplateRendererInterface::TEMPLATE_ALL, 'layout', false);
317+
318+
319+
$name = 'zendview';
320+
$rendered = $renderer->render('zendview', [ 'name' => $name ]);
321+
322+
$expected = file_get_contents(__DIR__ . '/TestAsset/zendview.phtml');
323+
$expected = str_replace('<?php echo $name ?>', $name, $expected);
324+
325+
$this->assertEquals($rendered, $expected);
326+
}
327+
282328
/**
283329
* @group namespacing
284330
*/

0 commit comments

Comments
 (0)