In this post I am going to explain how to get system configuration value in phtml file in Magento 2.
You can get system configuration field value programatically as below.
Add below code snippet in Block class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | protected $scopeConfig; public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, array $data = [] ) { $this->scopeConfig = $scopeConfig; parent::__construct($context, $data); } public function getConfigValue($value = '') { return $this->scopeConfig->getValue($value, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } |
Add below code snippet in template file.
1 2 3 4 5 | // call block function and get value of system config field as below. $configValue = $block->getConfigValue('sectionId/groupId/fieldId'); echo $configValue; |
Thats it. Enjoy Magento 2!!
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
Leave a Reply