I’m trying to migrate an existing project into SS.
It’s a one page site with content “blocks” managed by the CMS. I realise it would probably be easier to make all these blocks as part of the home page type/template/layout in the CMS.
That’s not how it was though and this is more an exercise of “I could do this before in the old system, can I do it in SS”.
What I want:
A model/module in the CMS to manage content blocks that is seperate to the idea of a page. I’m pretty sure I can do this from the Lessons series.
A controller for the home page. In here I’ll add css/js and get the data from the above model to make available in the view.
So, super simple…
Currently I’m stuck at the routes, I think. The home page always loads page.ss and skips the controller.
You can use Silverstripe Elemental to do that. It allows you to add pre-defined blocks into a page.
For the other issue, if you’re just having the home page managed in the CMS, you shouldn’t need any custom routing or special controllers, etc. it should just work out of the box. Just add your CSS / JS requirements to the init() function in PageController.php and you should be away.
I head to my root in the browser and nothing seems to hit the HomeController. It still goes to PageController.
If I remove the PageController and Page file(s) the admin throws a 500.
I suspect it is this route in cms which runs after everything that is causing your issue; not sure what is the best practice for overriding that though:
Yeah I’d agree with you - thanks for finding that. I started hacking at the Director class and my version of '':'HomeController' doesn’t show up. If I do a different URL segment like 'pain':'PainController' I can see it getting into the Director. If I use After - '*' as well has no effect.
I tried to create yml as mentioned below, but does not seems to work, looks like to bug. And if replace empty string ie ’ ’ with ‘home’: ‘SilverStripe\Lessons\HomePageController’, works fine.
Not sure if you solved your route issue. But I ran into the same issue with my routes, and seemed like I needed to add - ‘#modelascontrollerroutes’ to the “After” block of myroutes, like this;
You need a new Page type: Homepage.php (namespace MyProject/Layout)
Create a page with the type in the CMS
Create a .ss file at themes/THEMENAME/templates/MyProject/Layout/Layout/Homepage.ss
flush
ps: if you must override index function, make sure you also tell it which template to use for rendering, by calling renderWith function, and giving it the template name - otherwise you will get a blank page with nothing in it but only the echo
What I did in the end was similar to that @leochenftw
I’ve done it two different ways in different projects.
Neither used routes.yaml.
The first just used PageController::index to get the module entries and view the page with $this->customise()->renderWith().
The second uses a HomePage class, HomePageController and HomePage template in Layouts. I load the extra data later via an AJAX call to a method in the controller.