How to create new modules

There are 2 methods to create a new module:
  1. One it's used to build modules that based on specific IDs, managed by the administrator, can change their behavior (or contents).
  2. The other one is used to build modules that don't require an ID to change their behavior (or contents).
(All source code is available from version 3.0.0+)

First method

To illustrate the use of the first method we are going to create a new module called "Media galleries".
We want to manage the media galleries through the administration so the their content will be generated based on a specific ID (MediaGalleryCode).
  • Create the following database tables:
    • tb_cms_media_galleries
    • tb_cms_media_galleries_languages
    • tb_cms_media_items
    • tb_cms_media_items_languages
    • tb_cms_media_types
  • Create the following Stored Procedures and assign to each of them the EXECUTE permission for the database user specified in your connection string:
    • sp_cms_media_galleries_select
    • sp_cms_media_galleries_delete
    • sp_cms_media_galleries_insert_update
    • sp_cms_media_items_select
    • sp_cms_media_items_delete
    • sp_cms_media_items_insert
    • sp_cms_media_items_update
    • sp_cms_media_types_select
  • In the CMS administration (Permissions -> Admin pages) create the following pages right under the {#Content} page, alternatively you can add these entries directly in the database tables (tb_admin_pages and tb_admin_groups_pages_permissions):
{#MediaGalleries}
{#MediaGalleriesAddEdit}
{#MediaGalleriesDelete}
{#MediaItems}
{#MediaItemsAdd}
{#MediaItemsEdit}
  • Create the Model for BackEnd and FrontEnd:
    • ~/Models/MediaGalleries.cs
    • ~/Models/MediaItems.cs
    • ~/Models/MediaTypes.cs
  • Create the ViewModels for BackEnd:
    • ~/ViewModels/BackEndMediaGalleriesList.cs
    • ~/ViewModels/BackEndMediaGalleriesAddEdit.cs
    • ~/ViewModels/BackEndMediaItemsList.cs
    • ~/ViewModels/BackEndMediaItemsAddEdit.cs
  • Create the Controllers for BackEnd:
    • ~/Controllers/AdminMediaGalleriesController.cs
    • ~/Controllers/AdminMediaItemsController.cs
  • Create the Views for BackEnd:
    • ~/Views/Admin/MediaGalleries.cshtml
    • ~/Views/Admin/MediaGalleriesAddEdit.cshtml
    • ~/Views/Admin/MediaItems.cshtml
    • ~/Views/Admin/MediaItemsAddEdit.cshtml
  • Create a new Resource file for each language you want to deal with and add in there all the necessary strings:
    • ~/Resources/Strings_MediaGalleries.resx
    • ~/Resources/Strings_MediaGalleries.it.resx
Always try to reuse the existing strings from the main resx file (Strings.resx) and if not available add new items in the newly created file.
  • Install Galleria.js plugin
    • Download Galleria.js from http://galleria.io and unzip it in a temporary folder
    • Copy the galleria folder in the MVCwCMS project under the ~/Content/frontend/js/ folder
    • Move the galleria-1.4.2.js file under the ~/Content/shared/js/ folder and rename it as jquery.galleria-1.4.2.js
    • Create the mvcwcms-media-gallery.js file under the ~/Content/frontend/js/ folder.
    • Create the mvcwcms-media-gallery.css file under the ~/Content/frontend/css/ folder.
  • Under the folder ModuleConnectors create a new connector that implements the IModuleConnector interface:
    • MediaGalleriesConnector.cs - This file contains all the logic to build the HTML markup required by the Galleria plugin

Second method

To illustrate the use of the second method we are going to create a new module called "Contact".
  • Create the ViewModels for FrontEnd:
    • ~/ViewModels/FrontEndContact.cs
  • Create the Controllers for FrontEnd:
    • ~/Controllers/FrontEndContactController.cs
  • Create the Views for FrontEnd:
    • ~/Views/FrontEndContact/Index.cshtml
  • Create a new Resource file for each language you want to deal with and add in there all the necessary strings:
    • ~/Resources/Strings_Contact.resx
    • ~/Resources/Strings_Contact.it.resx
Always try to reuse the existing strings from the main resx file (Strings.resx) and if not available add new items in the newly created file.

Last edited Mar 16, 2015 at 9:47 AM by valgen, version 7