Skip to content

Commit

Permalink
Merge pull request #198 from thephpleague/default-layout-fixes
Browse files Browse the repository at this point in the history
Default Layout Fixes #183
  • Loading branch information
ragboyjr authored Jan 15, 2018
2 parents e066cc2 + a32c868 commit bdb4c5f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/Extension/LayoutSections/DefaultLayoutRenderTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public function __construct(Plates\RenderTemplate $render, $layout_path) {
}

public function renderTemplate(Plates\Template $template, Plates\RenderTemplate $rt = null) {
if ($template->parent || $template->get('no_layout')) {
return $this->render->renderTemplate($template, $rt ?: $this);
}

$ref = $template->reference;
$contents = $this->render->renderTemplate($template, $rt ?: $this);

if ($ref()->get('layout') || $ref()->get('is_default_layout')) {
return $contents;
}

$layout = $ref()->fork($this->layout_path, [], ['is_default_layout' => true]);
$layout = $ref()->fork($this->layout_path);
$ref()->with('layout', $layout->reference);

return $contents;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fixtures/default-layout/main.phtml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div>main</div>
<div>main - <?=$v->insert('partial')?></div>
1 change: 1 addition & 0 deletions test/integration/fixtures/default-layout/partial.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?='partial'?>
18 changes: 13 additions & 5 deletions test/integration/layout-sections.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
use League\Plates;

describe('Layout Sections Extension', function() {
it('allows default layout', function() {
$plates = new Plates\Engine([
beforeEach(function() {
$this->plates = new Plates\Engine([
'base_dir' => __DIR__ . '/fixtures/default-layout',
'default_layout_path' => './_layout',
]);

});
it('allows default layout on the root template', function() {
$html = <<<html
<div>
<div>main</div>
<div>main - partial</div>
</div>
html;
expect($plates->render('main'))->equal($html);
expect($this->plates->render('main'))->equal($html);
});
it('excludes any templates with no_layout attribute', function() {
$html = <<<html
<div>main - partial</div>
html;
expect($this->plates->render('main', [], ['no_layout' => true]))->equal($html);
});
});

0 comments on commit bdb4c5f

Please sign in to comment.