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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   732 Views

Avatar
JonShutt

Community Member, 244 Posts

27 June 2012 at 12:01pm

Hi,

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?

Avatar
Willr

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.

Avatar
JonShutt

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!