1

I created layout XML file for 2columns-left layout. I need to use two options 2columns-left and 2columns-right in system configuration. When admin selects 2columns-right it should set layout on Right side and vise versa.

How should i proceed?

enter image description here

HungryDB
9062 gold badges13 silver badges37 bronze badges
asked Aug 2, 2016 at 7:05
7
  • Hello, Please help me for above question. Commented Aug 16, 2016 at 5:10
  • 1
    I don't understand the question. Please use more words to make clear what you want to achieve, what did you do where and how, what happens and what you expected. Commented Aug 16, 2016 at 12:21
  • 1
    Refer :: magento.stackexchange.com/questions/128725/… OR magento.stackexchange.com/questions/85064/… Commented Aug 16, 2016 at 13:53
  • Don't understand of your question . Commented Aug 16, 2016 at 16:46
  • Check my updated question fschmengler and Paarth. Commented Aug 17, 2016 at 5:04

1 Answer 1

5
+50

If you are doing this for a page, I assume you have a controller action for that page.
You can do this in your controller action:

namespace [Namespace]\[Module]\Controller\[Something];
class SomeAction extends \Magento\Framework\App\Action\Action 
{
 protected $resultPageFactory;
 protected $scopeConfig;
 public function __construct(
 \Magento\Framework\App\Action\Context $context,
 \Magento\Framework\View\Result\PageFactory $resultPageFactory,
 \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
 ) {
 $this->resultPageFactory = $resultPageFactory;
 $this->scopeConfig = $scopeConfig;
 parent::__construct($context);
 }
 public function execute()
 {
 $page = $this->resultPageFactory->create();
 $layout = $this->scopeConfig->getValue(
 'path/to/config_value', 
 \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_STORE
 );
 if ($layout) {
 $page->getConfig()->setPageLayout($layout);
 }
 }
}

I haven't tested the code, so watch out for typos.

answered Aug 17, 2016 at 13:26
2
  • Hello Marius, when i try above code, front page is blank. Why? Commented Aug 29, 2016 at 9:50
  • 1
    try enabling the error reporting and see what's wrong Commented Aug 29, 2016 at 11:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.