0

I have a module for Homepage Banner. I have stated two system config fields inside the module- etc/adminhtml/system.xml.

enter image description here

I need the values of these fields in frontend phtml file "view/frontend/templates/html/banner.phtml".

How will I get these system config fields('enable' and 'banner_content_type') values?

3

Recommended way

<?php
namespace QaisarSatti\HelloWorld\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    public function getConfig($config_path)
    {
        return $this->scopeConfig->getValue(
            $config_path,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );
    }
}

get values in phtml

$helper = $this->helper('QaisarSatti\HelloWorld\Helper\Data');
$helper->getConfig('bannertab/settings/banner_content_type');
$helper->getConfig('bannertab/settings/enable');

Not Recommended way

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$conf = $objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('bannertab/settings/banner_content_type');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.