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 18 posts 143 karma points
    1 week ago
    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 3920 posts 13872 karma points mvp
    1 week ago
    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 18 posts 143 karma points
    1 week ago
    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 18 posts 143 karma points
    1 week ago
    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}\"]");
    
Please Sign in or register to post replies

Write your reply to:

Draft