How to use a custom url in the Products module - Solution
Hi,
If anybody is looking for a way to generate a seo friendly url with the category in it, then please use the following code-snippet for your module. The url will change from /2011/01/28/product-name to /category/product-name. This code needs to be placed in your openaccessdataprovider.cs.
Hope this helps somebody. I would not have been able to figure this out without the help of the amazing telerik support team - kudos to them.
public
override
string
GetUrlFormat(ILocatable item)
return
"/[CategoryName]/[UrlName]"
;
protected
override
string
GetUrlPart<T>(
string
key,
string
format, T item)
if
(key ==
"CategoryName"
)
return
this
.GetCategoryNameForItem(item);
return
base
.GetUrlPart<T>(key, format, item);
protected
string
GetCategoryNameForItem(IDataItem item)
if
(item ==
null
)
throw
new
ArgumentNullException(
"item"
);
string
category =
string
.Empty;
IContent content = (IContent)item;
IList<Guid> categoryIds = ((ProductItem)item).GetValue<IList<Guid>>(
"Category"
);
Guid firstCategoryId = categoryIds.FirstOrDefault();
if
(Guid.Empty != firstCategoryId)
var taxonManager = TaxonomyManager.GetManager();
category = taxonManager.GetTaxon(firstCategoryId).Name;
category = Regex.Replace(category,
"[^a-zA-Z0-9]"
,
"-"
);
return
category;
Hi Sonu,
Thank you for sharing this with the community. This will truly help a lot of people and save them time. We really appreciate when our clients actively share knowledge and help each other.
Kind regards,
Stanislav Velikov
the Telerik team
My pleassure Stanislav. It would have not been possible without your help. Thanks again.
Absolutely, a great help. I suggest Sitefinity team to start a knowledge base where they can publish with their solutions to clients problems. I am concern with solutions to problems that more than one site are facing. Knowledge base applications have more powerful search engines.
Thanks,
Zia
Absolutely, a great help. I suggest Sitefinity team to start a knowledge base where they can publish with their solutions to clients problems. I am concern with solutions to problems that more than one site are facing. Knowledge base applications have more powerful search engines.
Thanks,
Zia