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

Forums / Developing with Sitefinity / Filter on custom modules

Filter on custom modules

6 posts, 1 answered
  1. Rick
    Rick avatar
    15 posts
    Registered:
    15 Aug 2011
    18 Apr 2012
    Link to this post
    Hello,

    I have made a custom module, while looking at the reference code I found how to filter based on the URL name.

    DynamicContent produktenNachLokationen = dynamicModuleManager.GetDataItems(produktenNachLokationType).Where("UrlName = \"" + locationName + "\"").First();

    What I would like to do now is filter directly on a custom classification (name; Locations, type; Simple list) is this also possible?

    Thanks,
    Rick
  2. Josh
    Josh avatar
    13 posts
    Registered:
    10 Sep 2010
    19 Apr 2012
    Link to this post
    Hi Rick - 

    You need to get get the ID of the Taxonomy you wish to retrieve your records by and pass that in with your query. Here is an example:

    1.var taxonomy = TaxonomyManager.GetManager().GetTaxonomies<FlatTaxonomy>().Where(
    2.                    t => t.Name == "Region").Single().Taxa.Where(
    3.                        t => t.Title == this.Region).SingleOrDefault();
    1.DynamicContent produktenNachLokationen = dynamicModuleManager.GetDataItems(produktenNachLokationen)
    2.    .Where(x => x.UrlName == new Lstring(locationName) &&
    3.           x.GetValue<IList<Guid>>("Region").Equals(taxonomy.Id)).FirstOrDefault();

    You'll also need to include the Taxonomy namespaces and the GetValue extension which is located in Telerik.Sitefinity.Model.

    1.using Telerik.Sitefinity.Taxonomies;
    2.using Telerik.Sitefinity.Taxonomies.Model;
    3.using Telerik.Sitefinity.Model;

    Though, I haven't used any modules built with the module builder. All my modules are custom. But I'd venture to guess this is the same either way. Hope this helps you out!

    Cheers,
    Josh
    Answered
  3. Tys
    Tys avatar
    21 posts
    Registered:
    21 Jul 2011
    21 Apr 2012
    Link to this post
    Hi Josh,
    Thanks for helping! Your code seems to work just fine. The only thing is, the result set contains all module items twice! Any idea why that is?
    Kind regards, Tys
  4. Josh
    Josh avatar
    13 posts
    Registered:
    10 Sep 2010
    21 Apr 2012
    Link to this post
    Hi Tys - 

    No worries! It's pulling all the versions of the content. Try filtering by the live items. The where clause would look like this:

    .Where(x => x.UrlName == new Lstring(locationName) && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)

    Cheers,
    Josh
  5. Tys
    Tys avatar
    21 posts
    Registered:
    21 Jul 2011
    21 Apr 2012
    Link to this post
    Ah, forgot about that. Thanks! Now it works totally as it should!
  6. Josh
    Josh avatar
    13 posts
    Registered:
    10 Sep 2010
    21 Apr 2012
    Link to this post
    Ha! No worries. Glad it's working for ya!
6 posts, 1 answered