Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 510 posts 659 karma points
    Aug 14, 2013 @ 13:07
    andrew shearer
    0

    MNTP in Umbraco 6 - helper method?

    hopefully this is a simple question and its just a case of pointing me in the direction of the correct method..

    given a property based on the MNTP in umbraco 6, how do i obtain its nodes in a strongly typed fashion? (is there a built in way that doesn't involve the 'dynamic' namepace or a package?)

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 14, 2013 @ 13:29
    Dave Woestenborghs
    0

    Have a look at uQuery. 

    There are 2 methods that can help you, depending how you have configured the node picker (xml or csv)

    uQuery.GetNodesByCsv(string)
    uQuery.GetNodesByXml(string)

    More documentation can be found here : http://our.umbraco.org/documentation/Reference/Querying/uQuery/Content/Nodes

    Dave 

  • andrew shearer 510 posts 659 karma points
    Aug 15, 2013 @ 02:13
    andrew shearer
    0

    hi dawoe, thanks for the info.

    I was wondering if those uQuery methods had been updated or superceeded in umbraco 6 to deal with IPublishedContent rather than Node?

    I was reading this post from Shannon where he says that the old Node libraries are still there of course, but you shouldn't actually need to use them other than for backwards compatibility: http://shazwazza.com/post/Native-MVC-support-in-Umbraco-coming-very-soon! uQuery is still using the old Node libraries by the looks of things.

    There is an example here thats using TypedContent:

    https://github.com/Shandem/Umbraco4Docs/blob/4.8.0/Documentation/Reference/Mvc/querying.md

    ie. @Umbraco.TypedContent(1234, 4321, 1111, 2222)

    but that doesn't check those node ids are actually valid/published.

    If there is nothing currently in the Core for doing this then it appears my best option is to wrap TypedContent in my own extension method and check the items are actually published? 

  • andrew shearer 510 posts 659 karma points
    Aug 15, 2013 @ 02:46
    andrew shearer
    0

    for example, given a MNTP called "featuredItems" im currently doing this to obtain published content items within my homepage view:

    var featuredItems = Umbraco.TypedContent(Model.Content.GetPropertyValue<string>("featuredItems").Split(','))
    .ToList()
    .WhereNotNull();

    but I'd obviously rather not have all of that logic in a view.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Aug 15, 2013 @ 03:02
    Shannon Deminick
    0

    You can either create an extension method to do that for you, or you can create your own IPropertyEditorValueConverter for MNTP. We need to create more value converters as part of the core, there's already an issue logged for that here: http://issues.umbraco.org/issue/U4-1313

     

  • andrew shearer 510 posts 659 karma points
    Aug 15, 2013 @ 06:17
    andrew shearer
    0

    cool Shannon, thanks for the info and link. I'll take a look into IPropertyEditorValueConverter 


Please Sign in or register to post replies

Write your reply to:

Draft