Copied to clipboard

Flag this post as spam?

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


  • Andrew Unger 45 posts 148 karma points
    Jun 10, 2020 @ 12:31
    Andrew Unger
    0

    Issue rendering tags from multitreenode content

    enter image description here

    I have a multitreenode picker that is getting blog posts. On the blog posts themselves they have tags. I can't figure out how to properly render those tags. I get this error "Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object." I'm not sure how to make this work any help would be appreciated. The error happens at this line of code "foreach(var tag in post.GetPropertyValue<>

            @if (node.HasValue("featuredPosts"))
            {
                var blog = home.Descendant("blog");
                    <a href="#" style="visibility: hidden;">@node.GetPropertyValue("blogText", audiences.GetPropertyValue("blogText", "Blog"))</a>
                    <div>
                        <div id="audience-blog" class="row global-spacing">
                            <div class="section-header column small-12">
                                <h1>@Html.Raw(node.GetPropertyValue("blogHeader", "DIY <span>Blog</span>"))</h1>
                            </div>
    
                            <div id="blog-articles">
                                @foreach (var post in node.GetPropertyValue<IEnumerable<IPublishedContent>>("featuredPosts"))
                                {
                                var productMultiNodeTree = post.GetPropertyValue<IEnumerable<IPublishedContent>>("productsUsed");
                                    <div class="blog-item column small-12 medium-6">
                                        <a href="@post.Url">
                                            @if (post.HasValueImage("image"))
                                            {
                                                var i = post.GetPropertyValue<IPublishedContent>("image");
                                                <img src="@i.Url" alt="@i.GetPropertyValue("altTag")">
                                            }
                                            <h3 class="h5">@post.Name</h3>
                                            <div class="blog-type">
                                       <ul class="product">
                                        @foreach(var link in productMultiNodeTree) 
                                            { 
                                            <li><a href="@link.Url">@link.Name</a></li>
                                            }
                                        </ul>
                                        <ul class="project">
                                        @if(post.HasValue("tags")){
                                            foreach(var tag in post.GetPropertyValue<IEnumerable<string>>("tags")){
                                                <li><a href="@blogNode.Url?tag=@tag">@tag</a></li>
                                            }
                                        }
                                        </ul>
                                            </div>
                                        </a>
                                    </div>
                                }
                            </div>
                            @if (blog != null && blog.IsVisible())
                            {
                                <div class="column small-12 text-center">
                                    <a href="@blog.Url" class="button">
                                        @node.GetPropertyValue("viewFullBlogText", audiences.GetPropertyValue("viewFullBlogText", "View Full Blog"))
                                    </a>
                                </div>
                            }
                        </div>
                    </div>
            }
    
  • Steve Morgan 1346 posts 4453 karma points c-trib
    Jun 10, 2020 @ 13:06
    Steve Morgan
    0

    In your doc type check what the data type used for "tags" is?

    Also, what version of Umbraco are you using? The storage has changed on these - it used to be a bit more complicated to use them..

    https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Tags/index-vpost-7_4

    If you're struggling comment out that tags bit and try adding:

    <p>@(post.GetPropertyValue("tags")) </p>
    

    And post what is output here - it should be: System.String[]

  • Andrew Unger 45 posts 148 karma points
    Jun 10, 2020 @ 13:17
    Andrew Unger
    0

    yes when I did that I got System.String[]. I am using the tags from umbraco https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Tags/index-v7 I am using version 7.13.2

  • Andrew Unger 45 posts 148 karma points
    Jun 10, 2020 @ 14:21
    Andrew Unger
    0

    I found out the issue. It was actually breaking because "blogNode" wasn't set up correctly. I had to change it. It was

    var blogNode = node.AncestorOrSelf("blog");  
    

    I had to change it to

    var home = node.Site();
    var blogNode = home.DescendantOrSelf("blog");
    
Please Sign in or register to post replies

Write your reply to:

Draft