green field

Configuring Initial Content

Rate this Content 4 Votes

Last Updated 2009-01-28 Joe Audette

mojoPortal has a means by which you can configure what pages and features are created as initial content when a new site is created. This can be usefull if you have some custom application that you are packaging with mojoPortal and you want to be able to have a page created with your application on it. It is also usefull if you are using the mutli sites feature and wish to have some standard pages created whenever you create a new site. I use this feature myself on the demo.mojoportal.com site in order to populate it with some example pages with popular features. A default installation of mojoPortal also uses this but it only creates a single page with some introductory information.

If you look in the /Setup/initialcontent/pages folder, you will see the file 00001homepage.config that has the configuration for the home page created when mojoPortal is first installed. The name of the file is not important except that the sort order of the files determines the order in which pages are created. The file does need to end with a .config extension and it must have the correct xml format inside it.

Example:

<?xml version="1.0" encoding="utf-8" ?>
<siteContent>
<pages>
<page pageGuid="6ee971cd-9956-4dc3-8162-a488413e7f58"
resourceFile="Resource"
name="DefaultHomePageName"
title=""
url="~/home.aspx"
menuImage="home.gif"
parentGuid="00000000-0000-0000-0000-000000000000"
pageOrder="1"
requireSSL="false"
visibleToRoles="All Users;"
editRoles="Content Publishers;"
createChildPageRoles="Content Publishers;"
pageMetaKeyWords=""
pageMetaDescription=""
>
<contentFeature
featureGuid="881e4e00-93e4-444c-b7b0-6672fb55de10"
contentTitle="DefaultContentHtmlTitle"
contentTemplate="InitialSiteHomeContent.config"
location="center"
sortOrder="1"
cacheTimeInSeconds="360"
/>

</page>
</pages>
</siteContent>

The configuration allows you to define pages and to put instances of features on pages and give them a title. It is also possible with the Html Content feature to pre-populate the content based on additional configuration files. It is not currently possible to pre-populate content on any other features. For example you can create a page and put a Blog on it but you can't create a post in the blog currently.

It is designed to be localizable so that different content canbe created according to culture if content files exist for the specified culture. The culture is determined by the user's browser language preference. So if you are testing content for a specific culture you should set your browser to the preferred language before running the setup page. If no resource exists for the preferred language it will fall back to en-US.

So in the above configuration example the name of the home page comes from the ResourceKey "DefaultHomePageName" in the Resource.resx file, it the has their browser language preference set to German  it will get the string from the Resource.de.resx file instead of the English file Resource.resx. If the key is missing it will fall back to the English file. You can generate your own guids for each page andif you wish you can specify a parentGuid to create a hierarchal set of pages. If a page already exists with the specified guid it will just create a new guid for you because they must be unique. You can declare multiple pages in the same file or you can use additional files in the same folder if you want to use one config file per page.

Next you see the definition for the contentFeature, the featureGuid shown is for the Html Content feature. You can look up the featureGuid either in the db in the mp_ModuleDefinitions table or in the feature config files located under /Setup/applications/[FeatureName]/FeatureDefinitions folder.

The above example pre-populates the Html instance from the file /Data/MessageTemplates/en-US-InitialSiteHomeContent.config assuming the browser language is English or no resource exists for the browser language. To create a translation for German for example you would name the file de-DE-InitialSiteHomeContent.config. The title comes from the same Resource File as the page, in this case Resource.resx

A lot more could be done to improve this system and make it more flexible, but its a good start and meets the most common requirements.

Be aware that whenever you upgrade mojoPortal, the file /Setup/initialcopntent/pages/00001homepage.config will come back, so you may need to delete it after upgrading before you create new sites or that page will also be included.

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