This project is read-only.

Adding Site Settings

Oct 4, 2010 at 9:35 AM

Is there an elegant way that site wide settings can be created /extended for re-use in different modules. I am currently working on different modules that need common settings i.e smtp server name, smtp username, smtp password, mail from, mail to etc. What is the correct way of going about creating these under the Site Configuration Settings and then consuming these settings within various modules. Sample code would be greatly appreciated. If this issue was previously addressed I apologise and would appreciate a link to the discussion.

Oct 4, 2010 at 12:42 PM

Hi Garpo, there is a thread on the old forums that might help

Oct 4, 2010 at 1:02 PM

Hi Gareth, thank you for the link. Great to see that Messaging and Notification modules are part of the current iteration and it will cover the smtp settings quite nicely. I am however still curious as to how additional settings can be incorporated site wide and utilized across different modules.

Oct 4, 2010 at 1:50 PM

I know what you want because I've faced the same issue with another cms I was looking at. You don't want to be having web.config settings for custom settings you need them to be part of the cms. With Kooboo I setup a text schema just for email settings, the equivalent in Orchard is a content type built up of fields/parts.

To do this in Orchard I can see two options (I'm no Orchard expert by the way, just been looking at it recently and I've got 5 minutes in my dinner hour!)

1) You could setup a content type for each specific type of setting, create the data through Orchard admin and then I think you could use the ContentManager in your module to access your settings. Not tried this, I could do with a proof of concept of for my own purposes too

2) Alternatively you could write your own admin controller to manage settings records and use the excellent  IRepository ability of Orchard to easily persist objects to the database. You could then write a service for the settings that other modules could have injected into their constructor.

I may be utterly wrong, I'll look at this myself and maybe find a better way, but for now I'd better get back to work where I'm being taught how to use the waterfall method *head in hands*

Oct 4, 2010 at 3:57 PM

The most natural way to do it is to create a Site Settings Part. The Site content type is a content item unique for the website. Adding a specific Part to it will make this part unique also, and displayed in the Site Settings admin page, like all other site settings. For instance, there is a CommentsSiteSettingsPart to manage comments at the site level, or SearchSettingsPartRecord, .... There several other examples.

The easiest way to create one is to define a Record, say FooRecord, with the fields you want. Then a Handler, say FooHandler, with a Repository declaration and a TemplateForRecordFilter declaration which will let Orchard now what file is used as an Editor template. If you search for this class you will find how to make it.

Your question is dealing with Email settings, thus I would suggest you to take a look at the Messaging and the Email modules on the dev branch, which handle what you seem to do, sending email, and effectively also create Site Settings ;)