Custom URL Formats for Sitefinity Hierarchical Dynamic Modules

Custom URL Formats for Sitefinity Hierarchical Dynamic Modules

April 29, 2013 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

The following blog post is based on Slavo Ingilizov's blog post connected to custom URL formats for Sitefinity Content Modules. All hierarchical dynamic items in the Sitefinity CMS have URLs that are generated automatically from a given format. The default format includes the parent module item's name in the URL generated by hierarchical dynamic modules and item's title. The URL format of the hierarchical dynamic modules is configurable and this article explains how you can modify it.

The default structure of the hierarchical module items when one of them is opened in a browser is the following:

http://localhost:23740/test/parentitem/item

<---Page URL---><--Parent module item's URL--><--Item's URL name-->

Because there are two dynamic types in this case (Parent module and Child module), we can’t know if it specifies the URL of the parent module or the URL of the child module item. There is still a way to change the format in this case, but it involves some programming.

To remove the name of the parent module from the structure of the URL you need to create a custom provider and override a couple of methods. Please review the code below:
public class CustomProvider : Telerik.Sitefinity.DynamicModules.Data.OpenAccessDynamicModuleProvider
  {
      int temp = 0;
      public override string GetUrlFormat(Telerik.Sitefinity.GenericContent.Model.ILocatable item)
      {
          var resolvedItem = (DynamicContent)item;
          Type typeChild = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.TestModule1.Testmodule2");
          Type typeParent = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.TestModule1.Testmodule1");
          var type = resolvedItem.GetType();
          if (typeChild == type)
          {
              temp = 1;
  
              return "/[UrlName]";
          }
          if( temp > 0 )
          {
              if (typeParent == type)
          {
              resolvedItem.SystemUrl = "";
              return "";
          }
          }
          return "/[UrlName]";
      }
  }

The newly created class should inherit from: Telerik.Sitefinity.DynamicModules.Data.OpenAccessDynamicModuleProvider.
You need to override the GetUrlFormat method, which actually returns the format string and use the logic above in order to remove the parent name from the URL. You could return a different value in the code above, for example a value from a custom field that you have created for your custom provider.

The code will work for all of your new items, which are created in the new custom provider.

To use your new provider, you need to register it in Sitefinity. To do this, follow these steps below:

  1. Go to Administration –> Settings –> Advanced
  2. In the TreeView, open DynamicModules –> Providers.
  3. Click “Create New”
  4. Specify a Name and Title for your custom provider.
  5. For ProviderType, enter the full namespace and type of the custom class you previously created. 
  6. Restart the application
To create a new item, go to your custom provider section in your dynamic module and click the Create new button.

Please make sure that the URL which does not have a parent name in the structure is unique.
progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments
Comments are disabled in preview mode.
Topics
 
 
Latest Stories in
Your Inbox
Subscribe
More From Progress
New_Mobile_Dev_Ebook_Progress_Website_Thumbail
The New Mobile Development Landscape
Download Whitepaper
 
IDC Spotlight Sitefinity Thumbnail
Choosing the Right Digital Experience Platform to Improve Business Outcomes
Download Whitepaper
 
TheFastestWayToBuildMobileAppsArtboard-2
The Fastest Way to Build Mobile Apps With Cloud Data
Watch Webinar