It is possible to populate feature instance content when a site is created. As described in Configuring Initial Content, you can define which features are added to each page created with a new site. There are content installers already implemented for many of the features included in mojoPortal, and you can review the source code of those installers to learn how to implement a content installer for your own custom features. 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"
 contentInstaller="mojoPortal.Web.HtmlContentInstaller, mojoPortal.Web"

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:

using System.Globalization;
using System.IO;
using System.Text;
using System.Web.Hosting;
using mojoPortal.Business;
using mojoPortal.Web.Framework;

namespace mojoPortal.Web
    public class HtmlContentInstaller : IContentInstaller

        public void InstallContent(Module module, string configInfo)
            HtmlContent htmlContent = new HtmlContent();
            htmlContent.ModuleId = module.ModuleId;
            if (configInfo.StartsWith("~/"))
                if (File.Exists(HostingEnvironment.MapPath(configInfo)))
                    htmlContent.Body = File.ReadAllText(HostingEnvironment.MapPath(configInfo), Encoding.UTF8);
                htmlContent.Body = ResourceHelper.GetMessageTemplate(CultureInfo.CurrentCulture, configInfo);

            htmlContent.ModuleGuid = module.ModuleGuid;
            HtmlRepository repository = new HtmlRepository();


The else condition is for backward compatibility, where the content can come from text file under /Data/MessageTemplates and can be localized. The content can also 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 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 Modified by Joe Davis on Jul 29, 2022