Populating Feature Content
It is possible to populate feature instance content also when initial content is created for a new site. As you saw in Configuring Initial Content, you can define what features are added to a page. There are content installers already implemented for many of the features included in mojoPortal content management system, and you can study the source code of those installers to learn how to implement a content installer for your own custom features if you need to populate it when new sites are created. This example shows how we use the Html Content installer to configure some html content on the mojoPortal demo site.
contentTitle="mojoPortal Add On Product Demos"
Notice that the contentInstaller refers to the fully qualified type and assembly name of the class that is used to populate the content. This can be found in the mojoPortal source code under Web/Components/HtmlContentInstaller.cs. The full code for this is as follows:
public class HtmlContentInstaller : IContentInstaller
public void InstallContent(Module module, string configInfo)
HtmlContent htmlContent = new HtmlContent();
htmlContent.ModuleId = module.ModuleId;
htmlContent.Body = File.ReadAllText(HostingEnvironment.MapPath(configInfo), Encoding.UTF8);
htmlContent.Body = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentCulture, configInfo);
htmlContent.ModuleGuid = module.ModuleGuid;
HtmlRepository repository = new HtmlRepository();
Note that the else condition is for backward compatibility where the content can come from text file under /Data/MessageTemplates and can be localized. Or the content can come from anywhere if you start with ~/ to represent the root of the file system. This is a pretty simple implementation. Notice that it implements the IContentInstaller interface which defines one method signature. There are more complex examples of content installer also included in the source code for the Forums, Image Gallery, Folder Gallery, Feed Manager, and even WebStore. These were all designed mainly to help populate our demo site whenever it is reset. These examples can be a good reference for when you want to implement a content installer for your own feature.
Last Update 2011-03-30 by Joe Audette