Last active
September 27, 2016 10:05
-
-
Save timneutkens/d461cdaa4f57bdd36c78ac35304b793a to your computer and use it in GitHub Desktop.
Load a block based on deployment mode (development, default, production) Magento 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace TimNeutkens\Example\Block; | |
use Magento\Framework\App\State; | |
use Magento\Framework\View\Element\Template; | |
use Magento\Framework\View\Element\Template\Context; | |
class ExampleBlock extends Template { | |
protected $developerMode; | |
public function __construct(Context $context, array $data = []) { | |
/** @var State $state */ | |
$state = $context->getAppState(); | |
// Check if current mode is developer mode | |
$this->developerMode = $state->getMode() === $state::MODE_DEVELOPER; | |
// Create the template block | |
parent::__construct($context, $data); | |
} | |
public function _toHtml() { | |
// Don't render block when in developer mode | |
return !$this->developerMode ? parent::_toHtml() : ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment