Silverstripe Version: 4.9
Question: Can i change the $Layout from Controller?
Hello, I have a question about loading layout. There is any way for change the value of $Layout variable? for example i have a page with some specific params and i want to load different Layout for each params. For better understanding I have ?param=1 or ?param=2 And my goal is to have the same template but only modify $Layout between:
themes/mysite/templates/Layout/FirstLayout.ss
themes/mysite/templates/Layout/SecondLayout.ss
Maybe it’s easier to change the whole template for this controller i mean Page.ss and NumberLayout.ss
i was thinking about something like this
$SSViewer = new SSViewer();
if (param1) {
$SSViewer->setTemplateFile('Layout','themes/mysite/templates/Layout/FirstLayout.ss');
} else {
$SSViewer->setTemplateFile('Layout','themes/mysite/templates/Layout/SecondLayout.ss');
}
But i didint know how to download SSViewer in controller and change his $Layout variable
maybe there is another way to achive this…
https://api.silverstripe.org/4/SilverStripe/View/SSViewer.html#method_setTemplateFile
Or should i use it in index.php in root directory?
Anyway, thanks for help
Have a nice day!