Retrieving Data From Dynamic Modules Not Working

Posted by Community Admin on 03-Aug-2018 07:37

Retrieving Data From Dynamic Modules Not Working

All Replies

Posted by Community Admin on 08-Feb-2013 00:00

Following the examples on this page:

http://www.sitefinity.com/blogs/josh-morales-blog/2012/01/19/retrieving_data_from_dynamic_modules_using_the_module_builder_api

I've but the following code into the InitializeControls method in my, Thunder generated, widget with designer:

1.protected override void InitializeControls(GenericContainer container)
2.
3.    var dynamicModuleManager = DynamicModuleManager.GetManager();
4.    Type testimonialType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Testimonials.Testimonial");
5.    var testimonials = dynamicModuleManager.GetDataItems(testimonialType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
6.    dynamicContentListView.DataSource = testimonials;
7.    dynamicContentListView.DataBind();
8.

 

But it yields no results, even though I have created two testimonials.  The only thing that is majorily different than the examples is that it is a multisite configuration.

Am I missing something in this setup? Does it have to do with a multisite?

 

Posted by Community Admin on 12-Feb-2013 00:00

So you need to get the default provider for the current site and then use this provider when creating the DynamicModuleManager object.

1.// Make sure we are using the provider for the current site.
2. var provider = Sumo.Sitefinity.Framework.Model.MultisiteHelper.GetCurrentSite().GetDefaultProvider("Testimonials");
3. string providerName = null;
4. 
5. // the site doesn't have a default provider for 'Testimonials' so use the site provider.
6.providerName = (provider != null) ? provider.ProviderName : DynamicModuleManager.GetDefaultProviderName(); ;
7.DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);

Posted by Community Admin on 18-Apr-2014 00:00

Hi,

For DynamicModuleManager I am using this:

var provider = new MultisiteContext().CurrentSite.GetDefaultProvider("MODULE NAME");

Is there any way to get the module name using TypeResolutionService.ResolveType method? Module names can have spaces as well, so either we'll have to hard-code them in the code which is not a good practice at all. Or there must be some dynamic way for it.

This thread is closed