Skip to content

Commit 6344c6c

Browse files
committed
Add custom Block class that adds layout-name to cache key info
1 parent 7268cab commit 6344c6c

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

Block/LokiScript.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Loki\Base\Block;
4+
5+
use Magento\Framework\View\Element\Template;
6+
7+
class LokiScript extends Template
8+
{
9+
public function getCacheKeyInfo(): array
10+
{
11+
return [
12+
...parent::getCacheKeyInfo(),
13+
$this->getNameInLayout(),
14+
];
15+
}
16+
}

view/base/layout/loki_base.xml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
</block>
1919
</container>
2020

21-
<block name="loki.script" template="Loki_Base::script/script-container.phtml">
21+
<block
22+
name="loki.script"
23+
class="Loki\Base\Block\LokiScript"
24+
template="Loki_Base::script/script-container.phtml">
2225
<arguments>
2326
<argument name="cache_lifetime" xsi:type="number">86400</argument>
2427
</arguments>
@@ -32,7 +35,10 @@
3235
</block>
3336
</block>
3437

35-
<block name="loki.script.store" template="Loki_Base::script/script-container.phtml">
38+
<block
39+
name="loki.script.store"
40+
class="Loki\Base\Block\LokiScript"
41+
template="Loki_Base::script/script-container.phtml">
3642
<arguments>
3743
<argument name="cache_lifetime" xsi:type="number">86400</argument>
3844
</arguments>
@@ -46,27 +52,39 @@
4652
<block name="loki.script.store.messages" template="Loki_Base::script/store/message-store.phtml"/>
4753
</block>
4854

49-
<block name="loki.script.directive" template="Loki_Base::script/script-container.phtml">
55+
<block
56+
name="loki.script.directive"
57+
class="Loki\Base\Block\LokiScript"
58+
template="Loki_Base::script/script-container.phtml">
5059
<arguments>
5160
<argument name="cache_lifetime" xsi:type="number">86400</argument>
5261
</arguments>
5362

5463
<block name="loki.script.directive.autoremove" template="Loki_Base::script/directive/autoremove-directive.phtml"/>
5564
</block>
5665

57-
<block name="loki.script.component-partial" template="Loki_Base::script/script-container.phtml">
66+
<block
67+
name="loki.script.component-partial"
68+
class="Loki\Base\Block\LokiScript"
69+
template="Loki_Base::script/script-container.phtml">
5870
<arguments>
5971
<argument name="cache_lifetime" xsi:type="number">86400</argument>
6072
</arguments>
6173
</block>
6274

63-
<block name="loki.script.component-type" template="Loki_Base::script/script-container.phtml">
75+
<block
76+
name="loki.script.component-type"
77+
class="Loki\Base\Block\LokiScript"
78+
template="Loki_Base::script/script-container.phtml">
6479
<arguments>
6580
<argument name="cache_lifetime" xsi:type="number">86400</argument>
6681
</arguments>
6782
</block>
6883

69-
<block name="loki.script.component" template="Loki_Base::script/script-container.phtml">
84+
<block
85+
name="loki.script.component"
86+
class="Loki\Base\Block\LokiScript"
87+
template="Loki_Base::script/script-container.phtml">
7088
<arguments>
7189
<argument name="cache_lifetime" xsi:type="number">86400</argument>
7290
</arguments>

0 commit comments

Comments
 (0)