Skip to content

Commit 8688a7b

Browse files
authored
Fix missing view context when using blade layout components (#235)
1 parent 09b1df5 commit 8688a7b

File tree

18 files changed

+434
-370
lines changed

18 files changed

+434
-370
lines changed

src/Directives/SeoProDirective.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22

33
namespace Statamic\SeoPro\Directives;
44

5+
use Facades\Statamic\View\Cascade;
56
use Statamic\SeoPro\Tags\SeoProTags;
67

78
class SeoProDirective extends SeoProTags
89
{
910
public function renderTag($tag, $context)
1011
{
12+
if ($this->isMissingContext($context)) {
13+
$context = $this->getContextFromCascade();
14+
}
15+
1116
return $this->setContext($context)->$tag();
1217
}
18+
19+
protected function isMissingContext($context)
20+
{
21+
return ! isset($context['current_template']);
22+
}
23+
24+
protected function getContextFromCascade()
25+
{
26+
return Cascade::instance()->toArray();
27+
}
1328
}

tests/Fixtures/site-localized/content/collections/pages/default/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ updated_at: 1579284102
55
template: page
66
id: 62136fa2-9e5c-4c38-a894-a2753f02f5ff
77
---
8-
I'm just a kid living in the 90's, writing articles in his secret public journal wonder if someday, somewhere in the future, they will be read by someone.
8+
I'm just a kid living in the 90's, writing articles in his secret public journal wonder if someday, somewhere in the future, they will be read by someone.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: Articles
3-
template: articles.index
3+
template: page
44
updated_by: 96300192-873c-4615-b992-157508a8d7c5
55
updated_at: 1579283552
66
id: b9e4bfe3-9c12-4553-b7ef-f43c22ffaa63
77
---
8-
These are my various writings. Some might say they are cool.
8+
These are my various writings. Some might say they are cool.

tests/Fixtures/site-localized/content/collections/pages/default/home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Home
3-
template: home
3+
template: page
44
subtitle: 'I see pride. I see power.'
55
updated_by: b6c037ad-5bcc-41a8-a455-9ab54573f689
66
updated_at: 1606223924
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Home
3-
template: home
3+
template: page
44
subtitle: 'I see pride. I see power.'
55
updated_by: b6c037ad-5bcc-41a8-a455-9ab54573f689
66
updated_at: 1606223924
77
id: home
88
---
9-
I see a bad-ass mother.
9+
I see a bad-ass mother.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
title: Sneakers
2+
template: page
23
updated_by: 96300192-873c-4615-b992-157508a8d7c5
34
updated_at: 1579284942
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ template_content }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ seo_pro:meta }}
2+
<h1>antlers</h1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
@seo_pro('meta')
5+
</head>
6+
<body>
7+
{{ $slot }}
8+
</body>
9+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<x-layout>
2+
<h1>blade-components</h1>
3+
</x-layout>

0 commit comments

Comments
 (0)