2

I have two div's horizontally in one div there is Instagram feed plugin and another is the newsletter, now when Instagram feed plugin is disabled then newsletter should come in the whole space in Magento 2. enter image description here as you can see in the image now when Instagram feed is disabled hello should take the whole space

code to set width

<head>
<link rel="stylesheet" type="text/css" 
 href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/
 bootstrap.mi 
 n.css">
</head>
 <div>
<div class="row">
<div id="main1" class="col-md-6" style="border: 1px solid red;box- 
 sizing: border-box;">
    <h1>hello</h1>
</div>
<div id="main2" class="col-md-6" style="border: 1px solid black;box-sizing: border-box;">
    <h1>hello</h1>
</div>
</div>
</div>
 <script type="text/javascript">
   var main1 = document.getElementById('main1');
     var main2 = document.getElementById('main2');

   //main1.style.display = 'none';
   if(main1.style.display == "none")
      main2.className = "col-md-12";

    // if (true) {} else {}
 </script>
10
  • put your code in your post
    – fmsthird
    Commented Mar 14, 2019 at 4:49
  • you can put max-width
    – fmsthird
    Commented Mar 14, 2019 at 4:50
  • in which post?? Commented Mar 14, 2019 at 4:50
  • in your question you can put also your code so that it will be easy for others to help you
    – fmsthird
    Commented Mar 14, 2019 at 4:50
  • where to write the code for this width set i have code to set the width but where to write i dont know Commented Mar 14, 2019 at 4:51

2 Answers 2

0
For that first you have to check Instagram feed plugin is disable or not.
If disable than add directly set col-md-12 or if enable than set col-md-6.
<?php 
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        

    $moduleManager = $objectManager->get('\Magento\Framework\Module\Manager');

    $isEnabledModule=$moduleManager->isEnabled('YourNamespace_YourModule');

    if($isEnabledModule){
        $class="col-md-6";
    }
    else{
        $class="col-md-12";
    }
?>
<div>
<div class="row">
<?php if($isEnabledModule){ ?>
<div id="main1" class="col-md-6" style="border: 1px solid red;box- 
 sizing: border-box;">
    <h1>hello</h1>
</div>
<?php } ?>
<div id="main2" class="<?php echo $class; ?>" style="border: 1px solid black;box-sizing: border-box;">
    <h1>hello</h1>
</div>
</div>
</div>

2
  • but where to write that logic Commented Mar 14, 2019 at 5:41
  • Please check I write logic. Commented Mar 14, 2019 at 6:07
0

You have to do this, Add your external css in

app > design > fronted > [vendor] > [theme] > Magento_Theme > 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="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" src_type="url"/>
    </head>
</page>  

Then in your Magento admin, go to

Content > Pages
Look for Home Page page > Select Edit (under actions menu), then click on Content then insert your code:

<div>
<div class="row">
<div id="main1"  style="display: none; border: 1px solid red;box- 
 sizing: border-box;">

</div>
<div id="main2" class="col-md-6" style="border: 1px solid black;box-sizing: border-box;">
    <h1>hello</h1>
</div>
</div>
</div>
 <script type="text/javascript">
   var x = document.getElementById("main1");
  if (x.style.display === "none") {
   main2.className = "col-md-12";
  } 
</script>

and it should work after following above instructions

9
  • layout will be in view folder or outside in theme?? Commented Mar 14, 2019 at 5:40
  • as per your requirement you want to add it on home page, You can directly put your code in Admin > Content > Pages > (your Home Page - page) - Edit Page, and click on content then add your code > then save.
    – fmsthird
    Commented Mar 14, 2019 at 5:42
  • i am asking about defualt.xml file Commented Mar 14, 2019 at 5:42
  • you can do directly, outside in theme, in this path app > design > fronted > [vendor] > [theme] > Magento_Theme > layout > default.xml
    – fmsthird
    Commented Mar 14, 2019 at 5:43
  • 1
    okk let me check Commented Mar 14, 2019 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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