Retrieve custom module title
We have a module called blog categories built using the module builder. Using the code provided by the module builder i am able to retrieve all the blog categories. I can retrieve their ID, URLNAME etc. but there is no field called title in the returned object. there is also no GetValue() or similar method. Is there anyway i can retrieve the blog category title?
Hi Zubair. You need to add this namespace
using Telerik.Sitefinity.Model to using. And after that GetValue method will be availiable.
Let me know if you have any questions. If something not clear, please share piece of code, where you trying to receive title value
Hi,
That is correct, please observe following sample:
...
using Telerik.Sitefinity.Model;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type ArticlesType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.Articles.Article"
);
var Article = dynamicModuleManager.GetDataItems(ArticlesType).Where(a => a.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).FirstOrDefault();
//Get dynamic module item fields
var ArticleImage = Article.GetRelatedItems<Telerik.Sitefinity.Libraries.Model.Image>(
"ArticleImage"
).FirstOrDefault();
var ArticleTitle = Article.GetValue(
"Title"
).ToString();
imageUrl = ArticleImage.MediaUrl;
Hi Guys,
Thanks for your replies. Unfortunately the above solutions did not work. When i try the sample code suggested by Dimitri , I get the error Telerik.Sitefinity.DynamicModules.Model.DynamicContent does not contain a definition for GetRelatedItems .
If it helps I am using sitefinity 7.2. Initially i was using the following code to get all the blog categories:
public IQueryable<
DynamicContent
> RetrieveCollectionOfCategories()
// Set the provider name for the DynamicModuleManager here. All available providers are listed in
// Administration -> Settings -> Advanced -> DynamicModules -> Providers
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type categoryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BlogCategories.Category");
//CreateCategoryItem(dynamicModuleManager, categoryType);
// This is how we get the collection of Category items
var myCollection = dynamicModuleManager.GetDataItems(categoryType);
// At this point myCollection contains the items from type categoryType
return myCollection;
var CategoryList = RetrieveCollectionOfCategories().ToList();
foreach (var item in CategoryList)
// Can get URL successfully
string URL = item.UrlName;
//Trying to get Title
// string Title = item.Title;
Thanks,
Zubair
Hi,
The sample did use RelatedItems, which you most likely don't have.
However using
string
Title = item.GetValue(
"Title"
).ToString();
Thanks Guys. Dimitri's solution works.
I forgot to add the provider name thats why it was not showing up in Intellisense.