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 35 posts 304 karma points c-trib
    Nov 14, 2017 @ 15:18
    Jason Elkin

    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 6049 posts 23152 karma points MVP 5x admin c-trib
    Nov 14, 2017 @ 15:21
    Alex Skrypnyk

    Hi Jason

    "umb://document/1b7f16f0a9034dfeb3f7fb4fdd5b92f4" is an UDI, read more -

    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 35 posts 304 karma points c-trib
    Nov 14, 2017 @ 15:30
    Jason Elkin

    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 35 posts 304 karma points c-trib
    Nov 14, 2017 @ 15:47
    Jason Elkin

    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 44 posts 216 karma points c-trib
    Oct 03, 2018 @ 22:16
    Chris Kim

    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: