Custom Site Scope Settings - (sharing settings between modules)

Topics: Customizing Orchard
Dec 19, 2012 at 9:11 AM

I have created some custom site scope settings in a module that contains information that is used across all my modules.

Company.Core - holds Username, password, site settings etc.

Company.Widgets - widgets for the website, (has dependency to Company.Core).

How can I use the site scope settings defined in Company.Core by my Company.Widgets module?

Dec 19, 2012 at 9:36 AM

The same way that you use the settings in Company.Core: by casting the Site content item to your custom settings part, e.g. var settings = _orchardServices.WorkContext.CurrentSite.As<MyCustomSiteSettingsPart>();

Dec 21, 2012 at 11:20 AM

So I would need to have a reference to the Company.Core module in my Company.Widgets to reference Company.Core.MyCustomSiteSettingsPart

Dec 21, 2012 at 11:33 AM

You could, but you don't have to if you go the dynamic way:

var currentSite = (dynamic)_orchardServices.WorkContext.CurrentSite;
var settings = currentSite.MyCustomSiteSettingsPart;
var myCustomSetting1 = (string)settings.MyCustomSetting1;
var myCustomSetting2 = (int)settings.MyCustomSetting2;


Dec 21, 2012 at 12:11 PM

Aah, that's quite interesting. I didn't realise you could do that. Thanks a lot.