Copied to clipboard

Flag this post as spam?

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


  • Caley 14 posts 125 karma points
    Oct 15, 2022 @ 08:40
    Caley
    0

    Get content from another page / node

    I'm using Umbraco 10 and in a BlockList item I need to display some "Related posts" which basically is another page / node.

    The Related content is blog postes

    I'm using the "Multinode TreePicker" to choose the blog posts. So far so good – I can get various things like Url, Id, etc.

    (In my BlockListItem)
    
    var content      = Model.Content as BlogPost;
    var relatedPosts = content.RelatedPosts;
    
    foreach (var relatedPost in relatedPosts)
    {
           var url          = relatedPost.Url();
           var relatedName  = relatedPost.Name;
           var relatedId    = relatedPost.Id;
    }
    

    But how can I get the contents of the blog post? E.g. a Textstring (Umbraco.Textbox) named "blogName"

    In my head, it would be logic just to write:

    @relatedPost.BlogName
    

    or maybe

    @relatedPost.content.BlogName
    

    But it all fails. 😕

    I think I lack some basic understanding of the docs 😅

    Can someone please help me in the right direction?

  • Huw Reddick 1745 posts 6109 karma points MVP c-trib
    Oct 15, 2022 @ 15:05
    Huw Reddick
    100

    you'll need to cast your items similar to below

            @foreach (BlockListItem blockitem in content.DataItems)
            {
                TimelineData item = (TimelineData)blockitem.Content;
    
            }
    

    obviously your types will be different

  • Caley 14 posts 125 karma points
    Oct 15, 2022 @ 15:55
    Caley
    0

    Wow.. Okay! I spend the whole day yesterday searching for a solution and it turned out to be that simple.

    (Now In my BlockListItem)
    
    var content      = Model.Content as BlogPost;
    
    foreach (BlogPage relatedPost in content.RelatedPosts)
    {
           var url          = relatedPost.Url();
           var relatedName  = relatedPost.Name;
           var relatedId    = relatedPost.Id;
    
           var blogName     = relatedPost.BlogName; 
    }
    

    Thanks Huw!

Please Sign in or register to post replies

Write your reply to:

Draft