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;
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.
magento-2.1.7 category-attribute page-layouts
add a comment |
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.
magento-2.1.7 category-attribute page-layouts
add a comment |
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.
magento-2.1.7 category-attribute page-layouts
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.
magento-2.1.7 category-attribute page-layouts
magento-2.1.7 category-attribute page-layouts
asked Nov 22 '17 at 23:09
Juliano VargasJuliano Vargas
672625
672625
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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;
your code returns null. no matter what column I set to. thanks
– Juliano Vargas
Nov 23 '17 at 9:14
add a comment |
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
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
add a comment |
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!
New contributor
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
your code returns null. no matter what column I set to. thanks
– Juliano Vargas
Nov 23 '17 at 9:14
add a comment |
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;
your code returns null. no matter what column I set to. thanks
– Juliano Vargas
Nov 23 '17 at 9:14
add a comment |
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;
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;
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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!
New contributor
add a comment |
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!
New contributor
add a comment |
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!
New contributor
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!
New contributor
New contributor
answered Jun 12 at 14:22
Vernon GrantVernon Grant
11
11
New contributor
New contributor
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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