Retrieve custom module title

Posted by Community Admin on 04-Aug-2018 11:36

Retrieve custom module title

All Replies

Posted by Community Admin on 01-Jul-2016 00:00

 

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?

 

Posted by Community Admin on 01-Jul-2016 00:00

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

Posted by Community Admin on 04-Jul-2016 00:00

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;

 

Regards,
Dimitri Cools
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 04-Jul-2016 00:00

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;
        

And then iterating through the IQuerable to find the parameters :

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


           
        

Posted by Community Admin on 04-Jul-2016 00:00

Hi,
The sample did use RelatedItems, which you most likely don't have.

However using 

string Title = item.GetValue("Title").ToString();

in your sample works for me when test this (screenshot)
I hope the above information helps.

Regards,
Dimitri Cools
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 04-Jul-2016 00:00

Thanks Guys.  Dimitri's solution works. 

I forgot to add the provider name thats why it was not showing up in Intellisense.

This thread is closed