Model Class Generator For Sitecore Habitat

Posted 09/19/2016 by Yogeshwer Sharma

Model Class Generator For Sitecore Habitat is my first contribution in association with the NTTDATA to the Sitecore Marketplace.

The Model Class Generator helps to generates model classes of Sitecore data templates from Sitecore Content Tree. This module is useful if working with Sitecore Habitat. With the help of this module we can generate model class on any location dynamically.

This is a capability that existed using some Sitecore tools (like TDS and Glass Mapper), but it's sometimes difficult to tie those pieces together in the new Habitat architecture (especially since those are proprietary tools with support and training costs). I wanted to create a new tool to make that much simpler.

Installation of Model Class Generator

  1. Download Model.ClassGenerator-1.0.zip package from Sitecore Marketplace
  2. Install the Model.ClassGenerator-1.0.zip sitecore package from Sitecore installation wizard.
  3. After package installations add following command to your ~/App_Config/Commands.config file.

    <command name="devtools:generategmcode" type="Model.ClassGenerator.SitecoreApp.CustomItemGeneratorCommand,Model.ClassGenerator" />

  4. Then you will need to adjust the Class Generator Utility configuration file found here ~/App_Config/Include/ClassGeneratorUtility.config.

    There are two settings you have the be concerned with to start

    Base.Namespace - This will be the base namespace of the auto generated namespace for an item class.  The rest of the namespace you can provide from the sitecore at the time of generating classes.

    For example - We have multiple feature projects and all features will have basic namespace like Sitecore.Feature.[Feature Name] (Sitecore.Feature.Navigation).  So you can provide Sitecore.Feature in Base.Namespace section of config file and add [Feature Name] (Navigation) at the time of generating class.

    Base.FileOutputPath - This will be the base folder that the item class files will be written to.  The rest of the file path you can provide from the sitecore at the time of generating classes.

    For example - We have multiple feature projects and all features are placed on same location like D:\projects\features\[FeatureName]( D:\projects\features\ Navigation).  So you can provide D:\projects\features\ in Base. FileOutputPath section of config file and add [Feature Folder Name] (Navigation) at the time of generating class.

How to Use Model Class Generator

  1. Right click on the template folder for which template classes are needed to be generated. And then click on tools - > Generate Model Classes.

  2. It will open a modal window with checkbox list of all child items of selected template folder.
    1. Namespace - Enter the namespace value of your class.
    2. Class File Path – Enter folder location where you want to generate class.
    3. Templates Checkbox list – Select templates to generate class.

  3. Click on Generate button to generate class for selected templates with given Namespace and folder location.

  4. Now you can check generated class with name Template.cs on the given folder location.

Share:

Add your comment

 
 

 

Comments

  • Job said:
    11/2/2016 8:25 AM

    When clicked on Generate Model Classe(s), it pops up an error message dialog, which says " You can only run the Class Generator on Template Folder."

  • Yogesh said:
    1/11/2017 3:05 AM

    Job please select Template folder or template item to generate class

Archive

Syndication