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?
HungryDB
9062 gold badges13 silver badges37 bronze badges
asked Aug 2, 2016 at 7:05
-
Hello, Please help me for above question.Payal Patel– Payal Patel2016年08月16日 05:10:45 +00:00Commented Aug 16, 2016 at 5:10
-
1I 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.Fabian Schmengler– Fabian Schmengler2016年08月16日 12:21:08 +00:00Commented Aug 16, 2016 at 12:21
-
1Refer :: magento.stackexchange.com/questions/128725/… OR magento.stackexchange.com/questions/85064/…Ashish Jagnani– Ashish Jagnani2016年08月16日 13:53:28 +00:00Commented Aug 16, 2016 at 13:53
-
Don't understand of your question .Sourav– Sourav2016年08月16日 16:46:12 +00:00Commented Aug 16, 2016 at 16:46
-
Check my updated question fschmengler and Paarth.Payal Patel– Payal Patel2016年08月17日 05:04:41 +00:00Commented Aug 17, 2016 at 5:04
1 Answer 1
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
-
Hello Marius, when i try above code, front page is blank. Why?Payal Patel– Payal Patel2016年08月29日 09:50:33 +00:00Commented Aug 29, 2016 at 9:50
-
1try enabling the error reporting and see what's wrongMarius– Marius2016年08月29日 11:00:12 +00:00Commented Aug 29, 2016 at 11:00
default