MAGENTO 2 How to Get Current page layoutMagento2 : Get Current Page layoutGet Custom Category Attribute Value On Checkout PageCustom page layoutMagento 2 : Alternate Logo for Page LayoutHow to set two page layout in category page?magento 2 How to add a div in main tag with custom phtml template in custom moduleProduct Page Layout After SeachingMagento 2 : How to get subcategory details using main category url_keyMagento2 : Get Current Page layoutCall Menu Block on CMS Page from two column layout to one column layout in Magento 1.9Different category view XML for each page layout

How does DC work with natural 20?

Number of solutions mod p and Betti numbers

Why does cooking oatmeal starting with cold milk make it creamy?

Why does independence imply zero correlation?

When to remove insignificant variables?

How to remove this component from PCB

Does a vocal melody have any rhythmic responsibility to the underlying arrangement in pop music?

Will generated tokens be progressively stronger when using Cathar's Crusade and Sorin, Grim Nemesis?

Has there been any indication at all that further negotiation between the UK and EU is possible?

What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

What does it mean to not be able to take the derivative of a function multiple times?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Is there any proof that high saturation and contrast makes a picture more appealing in social media?

CircuiTikZ: Start ground relative to the closest component

Why don't countries like Japan just print more money?

Are all Ringwraiths called Nazgûl in LotR?

Boss wants someone else to lead a project based on the idea I presented to him

What happened to Steve's Shield in Iron Man 2?

Did the CIA blow up a Siberian pipeline in 1982?

Count All Possible Unique Combinations of Letters in a Word

Methodology: Writing unit tests for another developer

Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?

What is "industrial ethernet"?



MAGENTO 2 How to Get Current page layout


Magento2 : Get Current Page layoutGet Custom Category Attribute Value On Checkout PageCustom page layoutMagento 2 : Alternate Logo for Page LayoutHow to set two page layout in category page?magento 2 How to add a div in main tag with custom phtml template in custom moduleProduct Page Layout After SeachingMagento 2 : How to get subcategory details using main category url_keyMagento2 : Get Current Page layoutCall Menu Block on CMS Page from two column layout to one column layout in Magento 1.9Different category view XML for each page layout






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















How do I get current category "page_layout" value? e.g "1 column" or "2 column" and so on. The values from Layout screen shoot bellow.



enter image description here










share|improve this question




























    0















    How do I get current category "page_layout" value? e.g "1 column" or "2 column" and so on. The values from Layout screen shoot bellow.



    enter image description here










    share|improve this question
























      0












      0








      0


      1






      How do I get current category "page_layout" value? e.g "1 column" or "2 column" and so on. The values from Layout screen shoot bellow.



      enter image description here










      share|improve this question














      How do I get current category "page_layout" value? e.g "1 column" or "2 column" and so on. The values from Layout screen shoot bellow.



      enter image description here







      magento-2.1.7 category-attribute page-layouts






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '17 at 23:09









      Juliano VargasJuliano Vargas

      672625




      672625




















          3 Answers
          3






          active

          oldest

          votes


















          1














          You can inject BuilderInterface to your constructor



          public function __construct(
          MagentoFrameworkViewModelPageLayoutConfigBuilderInterface $pageLayoutBuilder
          )
          $this->pageLayoutBuilder = $pageLayoutBuilder;


          public function getLayouts()
          $pageLayout = [];
          $pageLayout = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
          unset($pageLayout[0]);
          return $pageLayout;






          share|improve this answer























          • your code returns null. no matter what column I set to. thanks

            – Juliano Vargas
            Nov 23 '17 at 9:14


















          0














          You need to create observer and inject MagentoFrameworkAppRequestHttp into the constructor



          public function __construct(
          ...
          MagentoFrameworkAppRequestHttp $request
          )
          ...
          $this->_request = $request;


          public function addCatalogToTopmenuItems(MagentoFrameworkEventObserver $observer)

          $full_action_name = $this->_request->getFullActionName();
          $layout = $observer->getEvent()->getLayout(); //Return layout name






          share|improve this answer























          • your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

            – Juliano Vargas
            Nov 23 '17 at 9:28



















          0














          I wanted to achieve the exact same thing. I ended up creating a helper class that injects both MagentoFrameworkViewResultPage and MagentoFrameworkViewLayout.



          The Page object can retrieve the selected layout using the method named getConfig()->getPageLayout(). But this method will return NULL if the page layout has not been selected in the admin area. So I ended up adding a custom method that will return the default page layout if no layout has been selected.



          Helper class example



          <?php

          namespace VendorNameModuleNameHelper;

          use MagentoFrameworkAppHelperAbstractHelper;

          class Data extends AbstractHelper


          /**
          * @var MagentoFrameworkViewResultPage
          */
          protected $_pageResult;

          /**
          * @var MagentoFrameworkViewLayout
          */
          protected $_layout;

          public function __construct(
          MagentoFrameworkAppHelperContext $context,
          MagentoFrameworkViewLayout $layout,
          MagentoFrameworkViewResultPage $pageResult)

          $this->_pageResult = $pageResult;
          $this->_layout = $layout;

          parent::__construct($context);


          /**
          * Will return the currect page layout.
          *
          * @return string The current page layout.
          */
          public function getCurrentPageLayout()

          $currentPageLayout = $this->_pageResult->getConfig()->getPageLayout();

          if (is_null($currentPageLayout))

          return $this->_layout->getUpdate()->getPageLayout();


          return $currentPageLayout;




          Template file usage



          <?php

          $data = $this->helper('VendorNameModuleNameHelperData');

          echo '<pre> Page Layout:' , $data->getCurrentPageLayout(), '</pre>';



          This might not be the best way to achieve this, but with Magento2's lack of documentation for developers, this is the only solution I could find that works in later versions of Magento2. I hope this helps!






          share|improve this answer








          New contributor



          Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















            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%2f202824%2fmagento-2-how-to-get-current-page-layout%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You can inject BuilderInterface to your constructor



            public function __construct(
            MagentoFrameworkViewModelPageLayoutConfigBuilderInterface $pageLayoutBuilder
            )
            $this->pageLayoutBuilder = $pageLayoutBuilder;


            public function getLayouts()
            $pageLayout = [];
            $pageLayout = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
            unset($pageLayout[0]);
            return $pageLayout;






            share|improve this answer























            • your code returns null. no matter what column I set to. thanks

              – Juliano Vargas
              Nov 23 '17 at 9:14















            1














            You can inject BuilderInterface to your constructor



            public function __construct(
            MagentoFrameworkViewModelPageLayoutConfigBuilderInterface $pageLayoutBuilder
            )
            $this->pageLayoutBuilder = $pageLayoutBuilder;


            public function getLayouts()
            $pageLayout = [];
            $pageLayout = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
            unset($pageLayout[0]);
            return $pageLayout;






            share|improve this answer























            • your code returns null. no matter what column I set to. thanks

              – Juliano Vargas
              Nov 23 '17 at 9:14













            1












            1








            1







            You can inject BuilderInterface to your constructor



            public function __construct(
            MagentoFrameworkViewModelPageLayoutConfigBuilderInterface $pageLayoutBuilder
            )
            $this->pageLayoutBuilder = $pageLayoutBuilder;


            public function getLayouts()
            $pageLayout = [];
            $pageLayout = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
            unset($pageLayout[0]);
            return $pageLayout;






            share|improve this answer













            You can inject BuilderInterface to your constructor



            public function __construct(
            MagentoFrameworkViewModelPageLayoutConfigBuilderInterface $pageLayoutBuilder
            )
            $this->pageLayoutBuilder = $pageLayoutBuilder;


            public function getLayouts()
            $pageLayout = [];
            $pageLayout = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
            unset($pageLayout[0]);
            return $pageLayout;







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '17 at 2:44









            mrtuvnmrtuvn

            1,93411830




            1,93411830












            • your code returns null. no matter what column I set to. thanks

              – Juliano Vargas
              Nov 23 '17 at 9:14

















            • your code returns null. no matter what column I set to. thanks

              – Juliano Vargas
              Nov 23 '17 at 9:14
















            your code returns null. no matter what column I set to. thanks

            – Juliano Vargas
            Nov 23 '17 at 9:14





            your code returns null. no matter what column I set to. thanks

            – Juliano Vargas
            Nov 23 '17 at 9:14













            0














            You need to create observer and inject MagentoFrameworkAppRequestHttp into the constructor



            public function __construct(
            ...
            MagentoFrameworkAppRequestHttp $request
            )
            ...
            $this->_request = $request;


            public function addCatalogToTopmenuItems(MagentoFrameworkEventObserver $observer)

            $full_action_name = $this->_request->getFullActionName();
            $layout = $observer->getEvent()->getLayout(); //Return layout name






            share|improve this answer























            • your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

              – Juliano Vargas
              Nov 23 '17 at 9:28
















            0














            You need to create observer and inject MagentoFrameworkAppRequestHttp into the constructor



            public function __construct(
            ...
            MagentoFrameworkAppRequestHttp $request
            )
            ...
            $this->_request = $request;


            public function addCatalogToTopmenuItems(MagentoFrameworkEventObserver $observer)

            $full_action_name = $this->_request->getFullActionName();
            $layout = $observer->getEvent()->getLayout(); //Return layout name






            share|improve this answer























            • your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

              – Juliano Vargas
              Nov 23 '17 at 9:28














            0












            0








            0







            You need to create observer and inject MagentoFrameworkAppRequestHttp into the constructor



            public function __construct(
            ...
            MagentoFrameworkAppRequestHttp $request
            )
            ...
            $this->_request = $request;


            public function addCatalogToTopmenuItems(MagentoFrameworkEventObserver $observer)

            $full_action_name = $this->_request->getFullActionName();
            $layout = $observer->getEvent()->getLayout(); //Return layout name






            share|improve this answer













            You need to create observer and inject MagentoFrameworkAppRequestHttp into the constructor



            public function __construct(
            ...
            MagentoFrameworkAppRequestHttp $request
            )
            ...
            $this->_request = $request;


            public function addCatalogToTopmenuItems(MagentoFrameworkEventObserver $observer)

            $full_action_name = $this->_request->getFullActionName();
            $layout = $observer->getEvent()->getLayout(); //Return layout name







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '17 at 4:34









            Rohan HapaniRohan Hapani

            1




            1












            • your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

              – Juliano Vargas
              Nov 23 '17 at 9:28


















            • your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

              – Juliano Vargas
              Nov 23 '17 at 9:28

















            your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

            – Juliano Vargas
            Nov 23 '17 at 9:28






            your code when return $layout it gives 500 checking server error logs there was no error in the logs. further debug shows that return $observer->getEvent() return "NULL" .

            – Juliano Vargas
            Nov 23 '17 at 9:28












            0














            I wanted to achieve the exact same thing. I ended up creating a helper class that injects both MagentoFrameworkViewResultPage and MagentoFrameworkViewLayout.



            The Page object can retrieve the selected layout using the method named getConfig()->getPageLayout(). But this method will return NULL if the page layout has not been selected in the admin area. So I ended up adding a custom method that will return the default page layout if no layout has been selected.



            Helper class example



            <?php

            namespace VendorNameModuleNameHelper;

            use MagentoFrameworkAppHelperAbstractHelper;

            class Data extends AbstractHelper


            /**
            * @var MagentoFrameworkViewResultPage
            */
            protected $_pageResult;

            /**
            * @var MagentoFrameworkViewLayout
            */
            protected $_layout;

            public function __construct(
            MagentoFrameworkAppHelperContext $context,
            MagentoFrameworkViewLayout $layout,
            MagentoFrameworkViewResultPage $pageResult)

            $this->_pageResult = $pageResult;
            $this->_layout = $layout;

            parent::__construct($context);


            /**
            * Will return the currect page layout.
            *
            * @return string The current page layout.
            */
            public function getCurrentPageLayout()

            $currentPageLayout = $this->_pageResult->getConfig()->getPageLayout();

            if (is_null($currentPageLayout))

            return $this->_layout->getUpdate()->getPageLayout();


            return $currentPageLayout;




            Template file usage



            <?php

            $data = $this->helper('VendorNameModuleNameHelperData');

            echo '<pre> Page Layout:' , $data->getCurrentPageLayout(), '</pre>';



            This might not be the best way to achieve this, but with Magento2's lack of documentation for developers, this is the only solution I could find that works in later versions of Magento2. I hope this helps!






            share|improve this answer








            New contributor



            Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.























              0














              I wanted to achieve the exact same thing. I ended up creating a helper class that injects both MagentoFrameworkViewResultPage and MagentoFrameworkViewLayout.



              The Page object can retrieve the selected layout using the method named getConfig()->getPageLayout(). But this method will return NULL if the page layout has not been selected in the admin area. So I ended up adding a custom method that will return the default page layout if no layout has been selected.



              Helper class example



              <?php

              namespace VendorNameModuleNameHelper;

              use MagentoFrameworkAppHelperAbstractHelper;

              class Data extends AbstractHelper


              /**
              * @var MagentoFrameworkViewResultPage
              */
              protected $_pageResult;

              /**
              * @var MagentoFrameworkViewLayout
              */
              protected $_layout;

              public function __construct(
              MagentoFrameworkAppHelperContext $context,
              MagentoFrameworkViewLayout $layout,
              MagentoFrameworkViewResultPage $pageResult)

              $this->_pageResult = $pageResult;
              $this->_layout = $layout;

              parent::__construct($context);


              /**
              * Will return the currect page layout.
              *
              * @return string The current page layout.
              */
              public function getCurrentPageLayout()

              $currentPageLayout = $this->_pageResult->getConfig()->getPageLayout();

              if (is_null($currentPageLayout))

              return $this->_layout->getUpdate()->getPageLayout();


              return $currentPageLayout;




              Template file usage



              <?php

              $data = $this->helper('VendorNameModuleNameHelperData');

              echo '<pre> Page Layout:' , $data->getCurrentPageLayout(), '</pre>';



              This might not be the best way to achieve this, but with Magento2's lack of documentation for developers, this is the only solution I could find that works in later versions of Magento2. I hope this helps!






              share|improve this answer








              New contributor



              Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                0












                0








                0







                I wanted to achieve the exact same thing. I ended up creating a helper class that injects both MagentoFrameworkViewResultPage and MagentoFrameworkViewLayout.



                The Page object can retrieve the selected layout using the method named getConfig()->getPageLayout(). But this method will return NULL if the page layout has not been selected in the admin area. So I ended up adding a custom method that will return the default page layout if no layout has been selected.



                Helper class example



                <?php

                namespace VendorNameModuleNameHelper;

                use MagentoFrameworkAppHelperAbstractHelper;

                class Data extends AbstractHelper


                /**
                * @var MagentoFrameworkViewResultPage
                */
                protected $_pageResult;

                /**
                * @var MagentoFrameworkViewLayout
                */
                protected $_layout;

                public function __construct(
                MagentoFrameworkAppHelperContext $context,
                MagentoFrameworkViewLayout $layout,
                MagentoFrameworkViewResultPage $pageResult)

                $this->_pageResult = $pageResult;
                $this->_layout = $layout;

                parent::__construct($context);


                /**
                * Will return the currect page layout.
                *
                * @return string The current page layout.
                */
                public function getCurrentPageLayout()

                $currentPageLayout = $this->_pageResult->getConfig()->getPageLayout();

                if (is_null($currentPageLayout))

                return $this->_layout->getUpdate()->getPageLayout();


                return $currentPageLayout;




                Template file usage



                <?php

                $data = $this->helper('VendorNameModuleNameHelperData');

                echo '<pre> Page Layout:' , $data->getCurrentPageLayout(), '</pre>';



                This might not be the best way to achieve this, but with Magento2's lack of documentation for developers, this is the only solution I could find that works in later versions of Magento2. I hope this helps!






                share|improve this answer








                New contributor



                Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                I wanted to achieve the exact same thing. I ended up creating a helper class that injects both MagentoFrameworkViewResultPage and MagentoFrameworkViewLayout.



                The Page object can retrieve the selected layout using the method named getConfig()->getPageLayout(). But this method will return NULL if the page layout has not been selected in the admin area. So I ended up adding a custom method that will return the default page layout if no layout has been selected.



                Helper class example



                <?php

                namespace VendorNameModuleNameHelper;

                use MagentoFrameworkAppHelperAbstractHelper;

                class Data extends AbstractHelper


                /**
                * @var MagentoFrameworkViewResultPage
                */
                protected $_pageResult;

                /**
                * @var MagentoFrameworkViewLayout
                */
                protected $_layout;

                public function __construct(
                MagentoFrameworkAppHelperContext $context,
                MagentoFrameworkViewLayout $layout,
                MagentoFrameworkViewResultPage $pageResult)

                $this->_pageResult = $pageResult;
                $this->_layout = $layout;

                parent::__construct($context);


                /**
                * Will return the currect page layout.
                *
                * @return string The current page layout.
                */
                public function getCurrentPageLayout()

                $currentPageLayout = $this->_pageResult->getConfig()->getPageLayout();

                if (is_null($currentPageLayout))

                return $this->_layout->getUpdate()->getPageLayout();


                return $currentPageLayout;




                Template file usage



                <?php

                $data = $this->helper('VendorNameModuleNameHelperData');

                echo '<pre> Page Layout:' , $data->getCurrentPageLayout(), '</pre>';



                This might not be the best way to achieve this, but with Magento2's lack of documentation for developers, this is the only solution I could find that works in later versions of Magento2. I hope this helps!







                share|improve this answer








                New contributor



                Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                share|improve this answer



                share|improve this answer






                New contributor



                Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                answered Jun 12 at 14:22









                Vernon GrantVernon Grant

                11




                11




                New contributor



                Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.




                New contributor




                Vernon Grant is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f202824%2fmagento-2-how-to-get-current-page-layout%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

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?