Magento 2.3 how to get store config value

please read first post Magento 2.3 create simple module to make configure opitons for theme.

we’ll read the values directly from app/code/Magebay/Themes/etc/adminhtml/system.xml

Magento 2.3 get store config value
The path config is section/grounp/value

Get value yes/no in xml file:

For example: create file <theme_dir>/Magebay_Themes/layout/default.xml then insert the following code.

<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
		<referenceContainer name="">
			<block ifconfig="themes/general/enable_topbanner" class="Magento\Framework\View\Element\Template"  name="top.banner" template="Magebay_Themes::html/mainBaner.phtml"/>

Then create file <theme_dir>/Magebay_Themes/templates/html/mainBaner.phtml then insert the following code.

<h1>Create banner here</h1>

Use helper get theme config then call it in template file:

For example: create file app/code/Magebay/Themes/Helper/Data.php then insert the following code.

namespace Magebay\Themes\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
    public function getConfig($path='')
        if($path) return $this->scopeConfig->getValue( $path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE );
        return $this->scopeConfig;

Update file <theme_dir>/Magebay_Themes/layout/default.xml should look like:

<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
		<referenceContainer name="after.body.start">
			<block class="Magento\Framework\View\Element\Template" after="-"  name="themes.configure" template="Magebay_themes::html/themeConfigure.phtml"/>
		<referenceContainer name="">
			<block ifconfig="themes/general/enable_topbanner" class="Magento\Framework\View\Element\Template"  name="top.banner" template="Magebay_themes::html/mainBaner.phtml"/>

Then create file <theme_dir>/Magebay_Themes/templates/html/themeConfigure.phtml then insert the following code.

	$cfg = $this->helper('Magebay\Themes\Helper\Data')->getConfig('themes/general/wellcome_text');
<p><?php echo $cfg; ?></p>

Use ObjectManager:

But it not an perfect choose, you should create simple module to customize your theme.

For example: go to backend enable top banner and upload banner img then update file <theme_dir>/Magebay_Themes/templates/html/mainBaner.phtml should look like.

	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
	$mediaUrl = $objectManager->get('Magento\Store\Model\StoreManagerInterface')
    $bannerUrl = $objectManager
	$bannerImgBg = $mediaUrl . 'themes/' . $bannerUrl;		
<?php if($bannerUrl!=''): ?>
<div class="top_banner">
	<img src="<?php echo $bannerImgBg; ?>" alt="" />
<?php endif; ?>

We was update our file structure looks as follows:

├── Themes/
│ ├── Helper/
│ │ ├── Data.php
├── Default/
│ ├── Magebay_Themes/
│ │ ├── layout/
│ │ │ ├── default.xml
│ │ ├── templates/
│ │ │ ├── html/
│ │ │ │ ├── themeConfigure.phtml
│ │ │ │ ├── mainBaner.phtml

For next post we’ll make custom page layout.