All posts in CMS

Working with SilverStripe without the CMS

Most users, and even developers only really Silverstripe as a great CMS (Content Management System). While that is true, it also a framework and can be used even without the CMS module installed.

Why?

Well this isn’t for everyone that use Silverstripe, but sometimes its nicer not to have the overhead of the CMS for something you are working with, especially if its more web app based rather than a website. Also if you really like the admin area of Silverstripe you needn’t worry as it is now mostly baked into the Framework module so removing the CMS doesn’t remove this feature as of SS 3.0. The biggest benefit in the CMS is maintaining the menu(and of course the page content), so if you really don’t do that all that much than working without it might be an idea..

In Silverstripe 3.1, it is now way easier to do this, especially if you are using composer, just don’t include it in your composer.json file!

Now we need to do add a few things to our installation so we can start working in the framework.

Routes!

As we don’t have any CMS to help us look up pages, in the DB we need to tell SS where to grab our content. Here is an example of a routes.yml (place this in _config folder in your mysites or project folder) file of a simple 3 page site.

Once we have these in place, and after /?flush=all we need to create our controllers to render some content.

Controllers

Like any MVC framework, Silverstripe uses Controllers to dispatch and return the work of our application. Above we would need to create 3 new Controllers named ‘HomeController’, ‘AboutController’ and ‘ContactController’ which all extend Controller.

The ‘index’ function is called by default on a controller, so now if you were to visit http://yourwebsite.blah/home, you should now see something.. of course with a little help from our friends ‘flush’ and ‘all’ you’d see something pop up in your browser.

Menu??

Without the CMS you don’t have access to creating and editing a menu. To get around this I would also recommend creating one more controller which oversees our controllers above. Lets call this SiteController, and this can house the menu system.

You can then loop the menu in your SS template file as you would normally. e.g.

<% loop $Menu %>

class=”current”<% end_if %>>$Title <% end_loop %>

That is all.

Please keep in mind this is a VERY barebones example of how to get things in Silverstripe working without the CMS installed. I plan on releasing a module to help people get off the ground faster from a few tricks I have learnt with the current project I am working. Please get in touch in the mean time if you would like to ask questions as I know there is very little documentation out there on the topic of Framework only work in Silverstripe.