Create Custom URL Format for Content Items Created using Module Builder
Hi,
How do you customize the URL for a custom module that is built using Module Builder?
For example, I've created a Module called Cars and a content item with the title of Car Number One. How would I output the URL as mysite/.../car-number-one instead of the default http://mysite/car-number-one?
I found a blog post that explains how to customize the URL formats for the News and Blogs module, http://www.sitefinity.com/blogs/slavoingilizov/posts/slavo-ingilizovs-blog/2011/10/19/custom_url_formats_for_sitefinity_content_modules, but it doesn't seem to work with modules created with Module Builder.
I am using Sitefinity 5.2.3800.0 standard.
Thanks
Hello Bryan,
I think there are two possible ways to achieve that. First one is by the blog post you have mentioned. I created a new file "CustomProvider" that will extend the dynamic module provider. Here is my CustomProvider.cs
using
Telerik.Sitefinity.DynamicModules.Data;
using
Telerik.Sitefinity.GenericContent.Model;
namespace
SitefinityWebApp
public
class
CustomProvider : OpenAccessDynamicModuleProvider
public
override
string
GetUrlFormat(ILocatable item)
string
urlFormat =
"/[UrlName]"
;
if
(item.GetType().FullName ==
"Telerik.Sitefinity.DynamicTypes.Model.Cars.Car"
)
urlFormat =
"/Cars/[UrlName]"
;
return
urlFormat;
It is required to check the content type of your item because the provider is common for all of the dynamic types. Build your solution, open Administration -> Settings -> Advanced -> DynamicModules -> Providers and create a new one. Set Title and Name to any value. For ProviderType enter your type, in my case SitefinityWebApp.CustomProvider, save and restart your application. You can see my settings here:
Then create some items in that provider and in the dynamic widgets change the provider property as shown in the blog post (you should have provider selector when the widget is opened for edit). Now by opening details view of the items urls should be with the correct format.
Another solution for that problem might be to create a page named "Cars" and make the dynamic content widget redirect to that page. I have recorded a short video demonstrating that -> http://screencast.com/t/2Q4xTVOvZP
I would like to mention that the trick with providers will work for Sitefinity versions after 5.2 while for 5.1 and before only the workaround with pages will work.
Kind regards,
Stoimen Stoimenov
the Telerik team