Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

IF Silverstripe Version == 3 {} else { }

Go to End

3 Posts   674 Views


Community Member, 244 Posts

27 June 2012 at 12:01pm


I'm making a shop module, I've been building for SS3, but a few servers I use won't run SS3, so i'm having to revert a few lines back to SS2.4 code. (eg, forms, datagrid)

I would like the module to work for both - the changes are quite small,

Is there a way of doing something like

IF ($SilverstripeVersion >= 3) {} else { }

so that I could make the code work for both system?


Forum Moderator, 5523 Posts

27 June 2012 at 6:25pm

Not another shop module! Ha so many popping up now. The short answer to your version question is no (that I'm aware of). You can do LeftAndMain::CMSVersion() to return the version information but this may not always be set. A common pattern is to check for a class which has been added (i.e class_exists('DataList') ? "3.X" : "2.X");

3.0 does have quite a few major changes (more template functionality) and new ORM which would make your code potential much cleaner in 3.0 so depending on how complex it is, you may find it easier with 2 branches.


Community Member, 244 Posts

27 June 2012 at 6:34pm

Hi Will

Yes - not-another-shop-module! I'm not releasing to the modules list, it's just something I use on a few website of my own for simple client shops, and I customise it to their needs.

At this stage there are only a couple of parts that need to be different for SS3, so I'll try and use your suggestions of checking if classes exist. As things move more to SS3 I'll take advantage of the extra stuff, but for now, i'm just trying to make things work with as little effort as possible!