green field

Module Settings - A Developer Convenience

Rate this Content 6 Votes

Often you will need to store configuration properties for your custom feature. For example the Contact Form Feature has a setting for the email address to send the message to when the form is posted. This is an instance level setting because I could have more than one Contact Form with different email addresses, so each instance of the Contact Form needs to store the instance specific setting somewhere.

You could implement your own system for managing settings in your feature and for very elaborate features that may be the best way to go, but for simple scenarios you can save some development effort by using the Module Settings system included in mojoPortal which allows you to store arbitrary properties that can be serialized as strings. You can define your settings as using either TextBox or CheckBox. When you use TextBox, you can also specify a RegularExpression used to validate values entered for the setting.

It is possible to define new module settings using the Site Administrative Features under Admin Menu > Feature Definitions > Feature Definition Settings, but typically its easier to just specify them in the FeatureDefinition file and then visit the Setup/Default.aspx page to run setup. It will add any missing Module Settings to the database based on your configuration file. Typically you put the FeatureDefinition files beneath Setup
 Applcations
   yourapplicationname
     FeatureDefinitions

See the examples for the included features under Setup/applications/mojoportal-core/FeatureDefinitions

You get to the Module Settings page for a feature instance by clicking the gears icon next to the title. There you will see a few core module properties defined in the SiteModuleControl base class and then you will see any custom feature specific module settings.

In the code for your ModuleControl (which inherits from SiteModuleControl) you can access settings from the intrinsic hashtable named Settings like this:

Settings["ContactFormEmailSetting"].ToString()

or

UseSpamBlocking = WebUtils.ParseBoolFromHashtable(
Settings, "ContactFormUseCommentSpamBlocker", false);

If your feature has supporting pages like the Blog and Forums do, you may need to be able to lookup these settings from there to. In that case you can get them like this:

Hashtable moduleSettings = ModuleSettings.GetModuleSettings(ModuleID);
ShowCategories = WebUtils.ParseBoolFromHashtable(
moduleSettings, "BlogShowCategoriesSetting", false);

For more complex settngs, you can implement a UserControl (ie .ascx) and implement ISettingControl. An example implementation is  /Controls/GMapTypeSetting.ascx which is used for choosing the map type in features that have google maps. You can look at /Setup/applications/mojoportal-core/FeatureDefinitions/50020_GoogleMapModule.config for an example configuration.

Last Updated 2008-08-16

Custom Skinning by Joe Davis Your advertisement here Nominate mojoPortal for the 2010 CMS Awards
Give your site more mojo! Your advertisement here mojoPortal User Group on Yamisee