File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Smile \React \Block ;
4+
5+ use Magento \Framework \View \Element \Template ;
6+
7+ /**
8+ * React bundle loading block.
9+ * Argument disabled allows to disable the block output, hence the loading of the bundle
10+ * through (layout) argument injection.
11+ *
12+ * @category Smile
13+ * @package Smile\React
14+ */
15+ class Script extends Template
16+ {
17+ /** @var bool */
18+ protected $ disabled = false ;
19+
20+ /**
21+ * Constructor.
22+ *
23+ * @param Template\Context $context Template context.
24+ */
25+ public function __construct (
26+ Template \Context $ context ,
27+ array $ data = []
28+ ) {
29+ parent ::__construct ($ context , $ data );
30+ $ this ->disabled = (bool ) ($ data ['disabled ' ] ?? false );
31+ }
32+
33+ /**
34+ * Render block HTML
35+ *
36+ * @return string
37+ */
38+ protected function _toHtml ()
39+ {
40+ if ($ this ->disabled ) {
41+ return '' ;
42+ }
43+
44+ return parent ::_toHtml ();
45+ }
46+ }
Original file line number Diff line number Diff line change 22<page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
33 <body >
44 <referenceContainer name =" before.body.end" >
5- <block name =" react.script" template =" Smile_React::script.phtml" />
5+ <block name =" react.script" class = " Smile\React\Block\Script " template =" Smile_React::script.phtml" />
66 </referenceContainer >
77 </body >
88</page >
Original file line number Diff line number Diff line change 11<?php
22declare (strict_types=1 );
33
4- use Magento \ Framework \ View \ Element \ Template ;
4+ use Smile \ React \ Block \ Script ;
55
6- /** @var $block Template */
6+ /** @var $block Script */
77?>
88<script src="<?= '/js/react.bundle.js ' ?> "></script>
You can’t perform that action at this time.
0 commit comments