Get MAGE_MODE within a template file or a block
-
01-10-2020 - |
سؤال
How can I get the current MAGE_MODE
value, defined in the env.php
file, from a template (.phtml) file or a block class?
المحلول
We can use getMode()
method in \Magento\Framework\App\State
class. In your block:
/** @var \Magento\Framework\App\State $_appState **/
protected $_appState;
public function __construct(
......
\Magento\Framework\App\State $appState
)
{
$this->_appState = $appState;
}
public function getMode() {
return $this->_appState->getMode();
}
لا تنتمي إلى magento.stackexchange