I would like to add option in Configuration for module Enabled Yes/No.

I have tried below code but not working. Can you please suggest me any change on it or need to add any anther file.

<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="0">
  • any error you face? – Sagar Dobariya Aug 4 '17 at 9:04
  • Not any Error, Just I put Code in syste.xml file and in Configuration I have set No . Still module data show into front-end. – Hitesh Vaghasiya Aug 4 '17 at 9:09

Add in your layout when phtml called use ifconfig="sectionid/groupid/fieldid" like this

<block class="Magento\Framework\View\Element\Template" template="vendorname_Modulename::your.phtml" ifconfig="sectionid/groupid/fieldid"/>

You can check module enable or disable in controller,block

namespace Companyname\Modulename\Controller\ControllerFolder;

class Index extends \Magento\Framework\App\Action\Action

    private $scopeConfig;

    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\Action\Context $context
    ) {

        $this->scopeConfig = $scopeConfig;

    public function execute()
        $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
        $enableConfig = $this->scopeConfig->getValue('sectionid/groupid/sectionid', $storeScope);
        if ($enableConfig) {
        } else {
  • Thanks for ans, This is also useful for my other question . But This is not useful for module disable. When I select No module is not showing in front-end like URL go with 404. – Hitesh Vaghasiya Aug 4 '17 at 10:04
  • 1
    @HiteshVaghasiya i have update answer check it – Sagar Dobariya Aug 4 '17 at 10:09

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.