سؤال

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();
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top