Copied to clipboard

Flag this post as spam?

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


  • Shawn Calvert 5 posts 94 karma points
    1 week ago
    Shawn Calvert
    0

    Multinode Treepicker 2 in partial

    I'm guessing this is something super simple, but I've hit a dead end.

    I am trying to render a MultiNode Treepicker2 datatype in a partial to reuse on multiple pages throughout my site.

    If I have the properties in a in single document type, and only use it on that template, this works as expected:

        @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        @using Umbraco.Web.Models;
    
        @{
            var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
            foreach (var item in typedMultiNodeTreePicker)
            {
                <p class="sidebar-ten-years-entry-title"><a href="@item.Url">@item.Name</a></p>
            }
         }
    

    but if I try to move those properties in a stand-alone content type to reuse in a partial across the site, this doesn't work:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    @using Umbraco.Web
    @using Umbraco.Web.Models;
    
    @{
        var tenyears = Umbraco.TypedContent(1687).Children("tenYearsAgoThisWeek");
        var typedMultiNodeTreePicker = tenyears.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
        foreach (var item in typedMultiNodeTreePicker)
        {
    
        }
     }
    

    this gives the error: System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue<T>(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments

    It seems like it should work, I'm misunderstanding something fundamental about how IPublishedContent works. Thank you

  • Søren Gregersen 91 posts 437 karma points c-trib
    1 week ago
    Søren Gregersen
    100

    Hi Shawn,

    You are trying to call a method that does not exist - tenyears is a list of children, not publishedcontent.

    You either need to iterate (foreach) the "tenyears"-list, or pick the first child

    @{
        var tenyears = Umbraco.TypedContent(1687).Children("tenYearsAgoThisWeek");
        foreach (var child in tenyears)
        {
            var typedMultiNodeTreePicker = child.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
            foreach (var item in typedMultiNodeTreePicker)
            {
                //render
            }
        }
    }
    
  • Shawn Calvert 5 posts 94 karma points
    1 week ago
    Shawn Calvert
    0

    It worked - that totally makes sense - thank you very much for taking the time!

Please Sign in or register to post replies

Write your reply to:

Draft