+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Retrieve custom module title

Retrieve custom module title

6 posts, 1 answered
  1. Zubair
    Zubair avatar
    3 posts
    Registered:
    14 Dec 2015
    01 Jul
    Link to this post

     

    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?

     

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    01 Jul in reply to Zubair
    Link to this post

    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

  3. Dimitri Cools
    Dimitri Cools avatar
    80 posts
    Registered:
    08 Dec 2016
    04 Jul
    Link to this post
    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
     
  4. Zubair
    Zubair avatar
    3 posts
    Registered:
    14 Dec 2015
    04 Jul
    Link to this post

    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


               
            

  5. Dimitri Cools
    Dimitri Cools avatar
    80 posts
    Registered:
    08 Dec 2016
    04 Jul
    Link to this post
    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
     
    Answered
  6. Zubair
    Zubair avatar
    3 posts
    Registered:
    14 Dec 2015
    04 Jul
    Link to this post

    Thanks Guys.  Dimitri's solution works. 

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

6 posts, 1 answered