Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ruben Verhaaf 14 posts 34 karma points
    Mar 01, 2012 @ 11:58
    Ruben Verhaaf
    0

    Umbraco 5 filter on ContentType in where clause

    How can I filter on content types? I am able to filter on values of custom properties, but cannot filter on content types. 

    This works: var accordeonGroups = DynamicModel.Children.Where("isAccordeonGroup == true");
    This does not: var accordeonGroups = DynamicModel.Children.Where("ContentType.Alias == \"accordeonGroup\"");

    I now use the first method, for which I first add a custom property 'isAccordeonGroup' to the content type and set it to true manually for every node of the type. This works fine, but is cumbersome and error-prone. 

    Is there another way to write the second where clause?

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 01, 2012 @ 12:06
    Anthony Dang
    0

    I'm not sure about DynamicModel as it is of type BendyObject.

    But for Model (of type Content) you do this:

    var nodes = Model.Children.Where(x => x.ContentType.Alias == "MyDocTypeAlias")

     

    Perhaps you could try

    DynamicModel.Children.Where("Alias == \"accordeonGroup\"");

    or

    DynamicModel.Children.Where("NodeTypeAlias == \"accordeonGroup\"");

  • Ruben Verhaaf 14 posts 34 karma points
    Mar 01, 2012 @ 14:25
    Ruben Verhaaf
    0

    Ah nice, that solves my issue :). 

    Thanks, I did not yet know Model would get me a lot more than just DynamicModel.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Mar 01, 2012 @ 15:49
    Anthony Dang
    0

    Persoanlly I dont like DynamicModel. I develop in VS and like the intellisense that Model gives.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft