Copied to clipboard

Flag this post as spam?

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


  • Jason Elkin 38 posts 351 karma points MVP 3x c-trib
    Nov 14, 2017 @ 15:18
    Jason Elkin
    0

    How does one use TypedContentAtXPath with MultiNodeTreePicker2

    Does anyone know what the below should look like to work with the new MultiNodeTreePicker2?

    Umbraco.TypedContentAtXPath($"//myDoctype[linkedDoc= {Model.Content.Id}]")
    

    I can see that the value for @linkedDoc is umb://document/1b7f16f0a9034dfeb3f7fb4fdd5b92f4 but I have no idea how to get the equivalent value for my current doc.

  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Nov 14, 2017 @ 15:21
    Alex Skrypnyk
    1

    Hi Jason

    "umb://document/1b7f16f0a9034dfeb3f7fb4fdd5b92f4" is an UDI, read more - https://our.umbraco.org/documentation/reference/querying/Udi

    You don't need to call "Umbraco.TypedContentAtXPath($"//myDoctype[@linkedDoc= {Model.Content.Id}]")", you can use selected cotent item directly in the razor.

    Just get all selected nodes with code like that:

    var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("featuredArticles");
    
  • Jason Elkin 38 posts 351 karma points MVP 3x c-trib
    Nov 14, 2017 @ 15:30
    Jason Elkin
    0

    I need all documents of type myDocType where the property value for linkedDoc is my current page - sorry, intial xpath was wrong. Have now fixed.

  • Jason Elkin 38 posts 351 karma points MVP 3x c-trib
    Nov 14, 2017 @ 15:47
    Jason Elkin
    101

    Thanks Alex for the link,

    It turns out this is two step process.

    var udi = new GuidUdi("document", this.GetKey());
    var linkedDocs = UmbracoHelper.TypedContentAtXPath($"//myDocType[linkedDoc=\"{udi}\"]");
    
  • Chris Kim 48 posts 254 karma points c-trib
    Oct 03, 2018 @ 22:16
    Chris Kim
    1

    This is useful, thanks.

    Just to expand, if you are allowing multiple items to be picked, you can use the xpath query contains:

    var linkedDocs = UmbracoHelper.TypedContentAtXPath($"//myDocType[contains(linkedDoc,\"{udi}\"]");
    
Please Sign in or register to post replies

Write your reply to:

Draft