Change the URL format of hierarchical dynamic modules

Overview

The URL of a hierarchical item is automatically generated and, by default, includes the URL of all of its parent items. For more information, see URLs of dynamic content items. Below are two examples you can use to change the URL format of dynamic content items.

Add a custom field to the URL of a dynamic item

When you use Sitefinity CMS Module Builder to create a dynamic module, by default, the URL of the dynamic items is constructed in the following way: <your site>/<page where item is displayed>/<item’s URL>. By default, the item URL is its title. This can result in duplicated URLs for items with the same title.

To avoid creating items with duplicate URLs, you  can build your item’s URL based on a field or combination of fields that are unique for every item. 

To do this, perform the following:

  1. Create an extension to the module provider, where you construct the URL format.
    You do this, by adding a new class to your project. You inherit from OpenAccessDynamicModuleProvider and override the GetUrlFormat method where you enter the desired URL.
    Use the following code example:

    In the above example, the URL of the items is based on the value of fields in the module, which are named Address, JobTitle, and UrlName. The Address and JobTitle are fields that you must create in the module, the UrlName is a built-in field.

    NOTE: All fields, used for the URL format must be text fields.

  2. Register the new provider.
    Perform the following:
    1. In the backend, click Administration » Settings » Advanced.
    2. In the tree on the left, click DynamicModules » Provider » Create new.
    3. Enter a Name and Title of the new provider.
    4. In field ProviderType, enter the type of the class that you created in Step 1.
      In the code example above, the type of the class is SitefinityWebApp.NewModuleBuilderProvider.
    5. Under the new provider, click Parameters » Create new.
    6. In Key, enter applicationName
    7. In Value, enter the name of your application, for example, myCustomProvider.

      NOTE: Do not use /DynamicModule for the value, because this name represents the default Sitefinity CMS provider.

  3. Restart the application.
    Your provider is created.

When you open the module and add new items, there are two providers available - Default and the new provider you added. If you have multiple sites, you must add the provider to the modules where you want to use it. For more information, see Share content providers of modules.
New items added to this new provider use the new URL format - /[Address]/[JobTitle]/[UrlName]

The new provider is displayed in all modules you create with the Module Builder, together with the Default provider. If you want to display only the new provider and hide the default one, preform the following procedure Filter by data provider the items displayed on backend pages.

Remove the parent item from the URL of the child item

The following procedure explains how to remove the parent item URL from the URL of a child item. To do this, you must create a custom provider and override some of the methods.

To remove the parent item of just a specific module and type, perform the following:
  1. Implement the custom provider.
    1. Create a new class and inherit from Telerik.Sitefinity.DynamicModules.Data.OpenAccessDynamicModuleProvider.
    2. Override the GetUrlFormat that returns the format string and use the following code to remove the parent URL of the parent item:

      In the above code, you can return a different value, for example, the value from a custom field that you have created for your custom provider.

  2. Register the new provider in Sitefinity.
  3. Republish all dynamic content items.
    To apply the new format to previously created items, you must republish them.
  4. Restart the application.

To remove the parent item of any type, perform the same procedure as above but use the following code snippet:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?