Have a option to enable/disable the module. I need to load admin page css when my module is enabled. No need...












0














I write css in path
app/code/my/module/view/adminhtml/layout/default.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="My_Module::css/menuformat.css"/>
</head>
</page>


Above code apply menuformat.css to all the admin pages whether my module is enabled or not



I am replacing



<css ifconfig="My_Module/general/enabled" src="My_Module::css/menuformat.css"/> 


It returns error



Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'css', attribute 'ifconfig': The attribute 'ifconfig' is not allowed.


How can i write?. I need css only active when my module is enable otherwise no need .



I am using magento 2.2



I have a option to enable and disable the module . while click enable/disable button it reflects core_config_data table . Based on the table data i need to load the css . If enable load , disable no need to load the css.










share|improve this question
























  • Possible duplicate of Custom css for custom block/phtml.
    – Sukumar Gorai
    yesterday










  • @SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
    – Sammu Sundar
    yesterday












  • You can check my answer. I think it should help you!
    – Sukumar Gorai
    23 hours ago
















0














I write css in path
app/code/my/module/view/adminhtml/layout/default.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="My_Module::css/menuformat.css"/>
</head>
</page>


Above code apply menuformat.css to all the admin pages whether my module is enabled or not



I am replacing



<css ifconfig="My_Module/general/enabled" src="My_Module::css/menuformat.css"/> 


It returns error



Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'css', attribute 'ifconfig': The attribute 'ifconfig' is not allowed.


How can i write?. I need css only active when my module is enable otherwise no need .



I am using magento 2.2



I have a option to enable and disable the module . while click enable/disable button it reflects core_config_data table . Based on the table data i need to load the css . If enable load , disable no need to load the css.










share|improve this question
























  • Possible duplicate of Custom css for custom block/phtml.
    – Sukumar Gorai
    yesterday










  • @SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
    – Sammu Sundar
    yesterday












  • You can check my answer. I think it should help you!
    – Sukumar Gorai
    23 hours ago














0












0








0







I write css in path
app/code/my/module/view/adminhtml/layout/default.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="My_Module::css/menuformat.css"/>
</head>
</page>


Above code apply menuformat.css to all the admin pages whether my module is enabled or not



I am replacing



<css ifconfig="My_Module/general/enabled" src="My_Module::css/menuformat.css"/> 


It returns error



Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'css', attribute 'ifconfig': The attribute 'ifconfig' is not allowed.


How can i write?. I need css only active when my module is enable otherwise no need .



I am using magento 2.2



I have a option to enable and disable the module . while click enable/disable button it reflects core_config_data table . Based on the table data i need to load the css . If enable load , disable no need to load the css.










share|improve this question















I write css in path
app/code/my/module/view/adminhtml/layout/default.xml



<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="My_Module::css/menuformat.css"/>
</head>
</page>


Above code apply menuformat.css to all the admin pages whether my module is enabled or not



I am replacing



<css ifconfig="My_Module/general/enabled" src="My_Module::css/menuformat.css"/> 


It returns error



Exception #0 (MagentoFrameworkConfigDomValidationException): Element 'css', attribute 'ifconfig': The attribute 'ifconfig' is not allowed.


How can i write?. I need css only active when my module is enable otherwise no need .



I am using magento 2.2



I have a option to enable and disable the module . while click enable/disable button it reflects core_config_data table . Based on the table data i need to load the css . If enable load , disable no need to load the css.







magento2 module adminhtml css default.xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Sourav

1,109413




1,109413










asked yesterday









Sammu Sundar

779




779












  • Possible duplicate of Custom css for custom block/phtml.
    – Sukumar Gorai
    yesterday










  • @SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
    – Sammu Sundar
    yesterday












  • You can check my answer. I think it should help you!
    – Sukumar Gorai
    23 hours ago


















  • Possible duplicate of Custom css for custom block/phtml.
    – Sukumar Gorai
    yesterday










  • @SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
    – Sammu Sundar
    yesterday












  • You can check my answer. I think it should help you!
    – Sukumar Gorai
    23 hours ago
















Possible duplicate of Custom css for custom block/phtml.
– Sukumar Gorai
yesterday




Possible duplicate of Custom css for custom block/phtml.
– Sukumar Gorai
yesterday












@SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
– Sammu Sundar
yesterday






@SukumarGorai , i need to load the css based on core_config_data table record. Above code is work for me . but i need to stop css when path "My_Module/general/enabled" is 0 in core_config_data table. so i try "ifconfig" attributes but it is not accepted. I need to stop the css while path "My_Module/general/enabled" is 0 in core_config_data table. I need to any alternate way to stop the css loading.
– Sammu Sundar
yesterday














You can check my answer. I think it should help you!
– Sukumar Gorai
23 hours ago




You can check my answer. I think it should help you!
– Sukumar Gorai
23 hours ago










2 Answers
2






active

oldest

votes


















1














Create a module with name STech_Css by following below steps:



Step 1:
Create registration.php under:




app/code/STech/Css/registration.php




with content:



<?php

MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Css',
__DIR__
);


Step 2:
Create module.xml under:




app/code/STech/Css/etc/module.xml




with content:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Css" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
<module name="Magento_Checkout"/>
<module name="Magento_Cms"/>
<module name="Magento_Catalog"/>
</sequence>
</module>
</config>


Step 3:
Create system.xml under:




app/code/STech/Css/etc/adminhtml/system.xml




with content:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="stech_css" translate="label" sortOrder="10">
<label>STech</label>
</tab>
<section id="css" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>CSS</label>
<tab>stech_css</tab>
<resource>STech_Css::css_config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>General Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
</group>
</section>
</system>
</config>


Step 4:
Create events.xml under:




app/code/STech/Css/etc/frontend/events.xml




with content:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="layout_load_before">
<observer name="stech_css_layout_render" instance="STechCssObserverLayoutRender" />
</event>
</config>


Step 5:
Create LayoutRender.php under:




app/code/STech/Css/Observer/LayoutRender.php




with content:



<?php
namespace STechCssObserver;

class LayoutRender implements MagentoFrameworkEventObserverInterface
{
const STECH_CSS_ENABLE = 'css/general/enable';

private $scopeConfig;

public function __construct(
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

public function execute(MagentoFrameworkEventObserver $observer)
{
$enable = $this->scopeConfig->getValue(self::STECH_CSS_ENABLE, MagentoStoreModelScopeInterface::SCOPE_STORE);
if($enable){
$observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode());
}
return $observer;
}

private function getXmlCode()
{
return '<head>
<css src="STech_Css::css/stech_custom.css"/>
</head>';
}
}


Step 6:
Create stech_custom.css under:




app/code/STech/Css/view/frontend/web/css/stech_custom.css




And css according to your requirement.



Flush the cache and run setup:upgrade, setup:di:compile and static:content:deploy.



Hope this helps!






share|improve this answer





























    0














    No need of add ifconfig attribute in css tag. Just use this code and setup upgrade module & deploy once.



    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
    <css src="My_Module::css/menuformat.css"/>
    </head>
    </page>



    php bin/magento s:up



    php bin/magento s:s:d or php bin/magento s:s:d -f







    share|improve this answer





















    • Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
      – Sammu Sundar
      yesterday










    • I need css is active only when the module is enabled
      – Sammu Sundar
      yesterday










    • Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
      – Rohan Hapani
      yesterday












    • My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
      – Sammu Sundar
      yesterday










    • While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
      – Sammu Sundar
      yesterday











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256708%2fhave-a-option-to-enable-disable-the-module-i-need-to-load-admin-page-css-when-m%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Create a module with name STech_Css by following below steps:



    Step 1:
    Create registration.php under:




    app/code/STech/Css/registration.php




    with content:



    <?php

    MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    'STech_Css',
    __DIR__
    );


    Step 2:
    Create module.xml under:




    app/code/STech/Css/etc/module.xml




    with content:



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="STech_Css" setup_version="0.0.1">
    <sequence>
    <module name="Magento_Backend"/>
    <module name="Magento_Sales"/>
    <module name="Magento_Quote"/>
    <module name="Magento_Checkout"/>
    <module name="Magento_Cms"/>
    <module name="Magento_Catalog"/>
    </sequence>
    </module>
    </config>


    Step 3:
    Create system.xml under:




    app/code/STech/Css/etc/adminhtml/system.xml




    with content:



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
    <tab id="stech_css" translate="label" sortOrder="10">
    <label>STech</label>
    </tab>
    <section id="css" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
    <class>separator-top</class>
    <label>CSS</label>
    <tab>stech_css</tab>
    <resource>STech_Css::css_config</resource>
    <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
    <label>General Configuration</label>
    <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
    <label>Module Enable</label>
    <source_model>MagentoConfigModelConfigSourceYesno</source_model>
    </field>
    </group>
    </section>
    </system>
    </config>


    Step 4:
    Create events.xml under:




    app/code/STech/Css/etc/frontend/events.xml




    with content:



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_load_before">
    <observer name="stech_css_layout_render" instance="STechCssObserverLayoutRender" />
    </event>
    </config>


    Step 5:
    Create LayoutRender.php under:




    app/code/STech/Css/Observer/LayoutRender.php




    with content:



    <?php
    namespace STechCssObserver;

    class LayoutRender implements MagentoFrameworkEventObserverInterface
    {
    const STECH_CSS_ENABLE = 'css/general/enable';

    private $scopeConfig;

    public function __construct(
    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
    ) {
    $this->scopeConfig = $scopeConfig;
    }

    public function execute(MagentoFrameworkEventObserver $observer)
    {
    $enable = $this->scopeConfig->getValue(self::STECH_CSS_ENABLE, MagentoStoreModelScopeInterface::SCOPE_STORE);
    if($enable){
    $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode());
    }
    return $observer;
    }

    private function getXmlCode()
    {
    return '<head>
    <css src="STech_Css::css/stech_custom.css"/>
    </head>';
    }
    }


    Step 6:
    Create stech_custom.css under:




    app/code/STech/Css/view/frontend/web/css/stech_custom.css




    And css according to your requirement.



    Flush the cache and run setup:upgrade, setup:di:compile and static:content:deploy.



    Hope this helps!






    share|improve this answer


























      1














      Create a module with name STech_Css by following below steps:



      Step 1:
      Create registration.php under:




      app/code/STech/Css/registration.php




      with content:



      <?php

      MagentoFrameworkComponentComponentRegistrar::register(
      MagentoFrameworkComponentComponentRegistrar::MODULE,
      'STech_Css',
      __DIR__
      );


      Step 2:
      Create module.xml under:




      app/code/STech/Css/etc/module.xml




      with content:



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
      <module name="STech_Css" setup_version="0.0.1">
      <sequence>
      <module name="Magento_Backend"/>
      <module name="Magento_Sales"/>
      <module name="Magento_Quote"/>
      <module name="Magento_Checkout"/>
      <module name="Magento_Cms"/>
      <module name="Magento_Catalog"/>
      </sequence>
      </module>
      </config>


      Step 3:
      Create system.xml under:




      app/code/STech/Css/etc/adminhtml/system.xml




      with content:



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
      <system>
      <tab id="stech_css" translate="label" sortOrder="10">
      <label>STech</label>
      </tab>
      <section id="css" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
      <class>separator-top</class>
      <label>CSS</label>
      <tab>stech_css</tab>
      <resource>STech_Css::css_config</resource>
      <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
      <label>General Configuration</label>
      <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
      <label>Module Enable</label>
      <source_model>MagentoConfigModelConfigSourceYesno</source_model>
      </field>
      </group>
      </section>
      </system>
      </config>


      Step 4:
      Create events.xml under:




      app/code/STech/Css/etc/frontend/events.xml




      with content:



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="layout_load_before">
      <observer name="stech_css_layout_render" instance="STechCssObserverLayoutRender" />
      </event>
      </config>


      Step 5:
      Create LayoutRender.php under:




      app/code/STech/Css/Observer/LayoutRender.php




      with content:



      <?php
      namespace STechCssObserver;

      class LayoutRender implements MagentoFrameworkEventObserverInterface
      {
      const STECH_CSS_ENABLE = 'css/general/enable';

      private $scopeConfig;

      public function __construct(
      MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
      ) {
      $this->scopeConfig = $scopeConfig;
      }

      public function execute(MagentoFrameworkEventObserver $observer)
      {
      $enable = $this->scopeConfig->getValue(self::STECH_CSS_ENABLE, MagentoStoreModelScopeInterface::SCOPE_STORE);
      if($enable){
      $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode());
      }
      return $observer;
      }

      private function getXmlCode()
      {
      return '<head>
      <css src="STech_Css::css/stech_custom.css"/>
      </head>';
      }
      }


      Step 6:
      Create stech_custom.css under:




      app/code/STech/Css/view/frontend/web/css/stech_custom.css




      And css according to your requirement.



      Flush the cache and run setup:upgrade, setup:di:compile and static:content:deploy.



      Hope this helps!






      share|improve this answer
























        1












        1








        1






        Create a module with name STech_Css by following below steps:



        Step 1:
        Create registration.php under:




        app/code/STech/Css/registration.php




        with content:



        <?php

        MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'STech_Css',
        __DIR__
        );


        Step 2:
        Create module.xml under:




        app/code/STech/Css/etc/module.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
        <module name="STech_Css" setup_version="0.0.1">
        <sequence>
        <module name="Magento_Backend"/>
        <module name="Magento_Sales"/>
        <module name="Magento_Quote"/>
        <module name="Magento_Checkout"/>
        <module name="Magento_Cms"/>
        <module name="Magento_Catalog"/>
        </sequence>
        </module>
        </config>


        Step 3:
        Create system.xml under:




        app/code/STech/Css/etc/adminhtml/system.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
        <system>
        <tab id="stech_css" translate="label" sortOrder="10">
        <label>STech</label>
        </tab>
        <section id="css" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
        <class>separator-top</class>
        <label>CSS</label>
        <tab>stech_css</tab>
        <resource>STech_Css::css_config</resource>
        <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>General Configuration</label>
        <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>Module Enable</label>
        <source_model>MagentoConfigModelConfigSourceYesno</source_model>
        </field>
        </group>
        </section>
        </system>
        </config>


        Step 4:
        Create events.xml under:




        app/code/STech/Css/etc/frontend/events.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="layout_load_before">
        <observer name="stech_css_layout_render" instance="STechCssObserverLayoutRender" />
        </event>
        </config>


        Step 5:
        Create LayoutRender.php under:




        app/code/STech/Css/Observer/LayoutRender.php




        with content:



        <?php
        namespace STechCssObserver;

        class LayoutRender implements MagentoFrameworkEventObserverInterface
        {
        const STECH_CSS_ENABLE = 'css/general/enable';

        private $scopeConfig;

        public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
        ) {
        $this->scopeConfig = $scopeConfig;
        }

        public function execute(MagentoFrameworkEventObserver $observer)
        {
        $enable = $this->scopeConfig->getValue(self::STECH_CSS_ENABLE, MagentoStoreModelScopeInterface::SCOPE_STORE);
        if($enable){
        $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode());
        }
        return $observer;
        }

        private function getXmlCode()
        {
        return '<head>
        <css src="STech_Css::css/stech_custom.css"/>
        </head>';
        }
        }


        Step 6:
        Create stech_custom.css under:




        app/code/STech/Css/view/frontend/web/css/stech_custom.css




        And css according to your requirement.



        Flush the cache and run setup:upgrade, setup:di:compile and static:content:deploy.



        Hope this helps!






        share|improve this answer












        Create a module with name STech_Css by following below steps:



        Step 1:
        Create registration.php under:




        app/code/STech/Css/registration.php




        with content:



        <?php

        MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'STech_Css',
        __DIR__
        );


        Step 2:
        Create module.xml under:




        app/code/STech/Css/etc/module.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
        <module name="STech_Css" setup_version="0.0.1">
        <sequence>
        <module name="Magento_Backend"/>
        <module name="Magento_Sales"/>
        <module name="Magento_Quote"/>
        <module name="Magento_Checkout"/>
        <module name="Magento_Cms"/>
        <module name="Magento_Catalog"/>
        </sequence>
        </module>
        </config>


        Step 3:
        Create system.xml under:




        app/code/STech/Css/etc/adminhtml/system.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
        <system>
        <tab id="stech_css" translate="label" sortOrder="10">
        <label>STech</label>
        </tab>
        <section id="css" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
        <class>separator-top</class>
        <label>CSS</label>
        <tab>stech_css</tab>
        <resource>STech_Css::css_config</resource>
        <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>General Configuration</label>
        <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
        <label>Module Enable</label>
        <source_model>MagentoConfigModelConfigSourceYesno</source_model>
        </field>
        </group>
        </section>
        </system>
        </config>


        Step 4:
        Create events.xml under:




        app/code/STech/Css/etc/frontend/events.xml




        with content:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="layout_load_before">
        <observer name="stech_css_layout_render" instance="STechCssObserverLayoutRender" />
        </event>
        </config>


        Step 5:
        Create LayoutRender.php under:




        app/code/STech/Css/Observer/LayoutRender.php




        with content:



        <?php
        namespace STechCssObserver;

        class LayoutRender implements MagentoFrameworkEventObserverInterface
        {
        const STECH_CSS_ENABLE = 'css/general/enable';

        private $scopeConfig;

        public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
        ) {
        $this->scopeConfig = $scopeConfig;
        }

        public function execute(MagentoFrameworkEventObserver $observer)
        {
        $enable = $this->scopeConfig->getValue(self::STECH_CSS_ENABLE, MagentoStoreModelScopeInterface::SCOPE_STORE);
        if($enable){
        $observer->getLayout()->getUpdate()->addUpdate($this->getXmlCode());
        }
        return $observer;
        }

        private function getXmlCode()
        {
        return '<head>
        <css src="STech_Css::css/stech_custom.css"/>
        </head>';
        }
        }


        Step 6:
        Create stech_custom.css under:




        app/code/STech/Css/view/frontend/web/css/stech_custom.css




        And css according to your requirement.



        Flush the cache and run setup:upgrade, setup:di:compile and static:content:deploy.



        Hope this helps!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 23 hours ago









        Sukumar Gorai

        6,3853527




        6,3853527

























            0














            No need of add ifconfig attribute in css tag. Just use this code and setup upgrade module & deploy once.



            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <css src="My_Module::css/menuformat.css"/>
            </head>
            </page>



            php bin/magento s:up



            php bin/magento s:s:d or php bin/magento s:s:d -f







            share|improve this answer





















            • Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
              – Sammu Sundar
              yesterday










            • I need css is active only when the module is enabled
              – Sammu Sundar
              yesterday










            • Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
              – Rohan Hapani
              yesterday












            • My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
              – Sammu Sundar
              yesterday










            • While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
              – Sammu Sundar
              yesterday
















            0














            No need of add ifconfig attribute in css tag. Just use this code and setup upgrade module & deploy once.



            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <css src="My_Module::css/menuformat.css"/>
            </head>
            </page>



            php bin/magento s:up



            php bin/magento s:s:d or php bin/magento s:s:d -f







            share|improve this answer





















            • Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
              – Sammu Sundar
              yesterday










            • I need css is active only when the module is enabled
              – Sammu Sundar
              yesterday










            • Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
              – Rohan Hapani
              yesterday












            • My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
              – Sammu Sundar
              yesterday










            • While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
              – Sammu Sundar
              yesterday














            0












            0








            0






            No need of add ifconfig attribute in css tag. Just use this code and setup upgrade module & deploy once.



            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <css src="My_Module::css/menuformat.css"/>
            </head>
            </page>



            php bin/magento s:up



            php bin/magento s:s:d or php bin/magento s:s:d -f







            share|improve this answer












            No need of add ifconfig attribute in css tag. Just use this code and setup upgrade module & deploy once.



            <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <head>
            <css src="My_Module::css/menuformat.css"/>
            </head>
            </page>



            php bin/magento s:up



            php bin/magento s:s:d or php bin/magento s:s:d -f








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            Rohan Hapani

            5,82721662




            5,82721662












            • Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
              – Sammu Sundar
              yesterday










            • I need css is active only when the module is enabled
              – Sammu Sundar
              yesterday










            • Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
              – Rohan Hapani
              yesterday












            • My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
              – Sammu Sundar
              yesterday










            • While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
              – Sammu Sundar
              yesterday


















            • Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
              – Sammu Sundar
              yesterday










            • I need css is active only when the module is enabled
              – Sammu Sundar
              yesterday










            • Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
              – Rohan Hapani
              yesterday












            • My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
              – Sammu Sundar
              yesterday










            • While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
              – Sammu Sundar
              yesterday
















            Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
            – Sammu Sundar
            yesterday




            Fine @RohanHapani , But this is always active. i can disable and enable the module. At the time of disable also this css is active in all admin pages
            – Sammu Sundar
            yesterday












            I need css is active only when the module is enabled
            – Sammu Sundar
            yesterday




            I need css is active only when the module is enabled
            – Sammu Sundar
            yesterday












            Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
            – Rohan Hapani
            yesterday






            Please check your module entry enable disable from app/etc/config.php file. Set your module entry to '0' and flush cache and remove generated.
            – Rohan Hapani
            yesterday














            My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
            – Sammu Sundar
            yesterday




            My module is always enabled in app/etc/config.php file . It changes only in core_config_data table only
            – Sammu Sundar
            yesterday












            While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
            – Sammu Sundar
            yesterday




            While click the enable/disable button it does not reflect in app/etc/config.php file . Only reflect in core_config_data table
            – Sammu Sundar
            yesterday


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f256708%2fhave-a-option-to-enable-disable-the-module-i-need-to-load-admin-page-css-when-m%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            An IMO inspired problem

            Management

            Has there ever been an instance of an active nuclear power plant within or near a war zone?