Copied to clipboard

Flag this post as spam?

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


  • Emanuel Nilsson 3 posts 73 karma points
    Aug 31, 2018 @ 07:01
    Emanuel Nilsson
    0

    SmartBlog on Umbraco 7.12.1

    Hi,

    I'm running Umbraco version 7.12.1 and SmartBlog 2.2.1.

    In order to get it working I have done some fixes to SmartListTags.cshtml and SmartListCategories.cshtml.

    Everything seems to work fine except the SmartBlog Manager. getPropertyValue() and getPost() in smartBlogManagement.asx returns "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

    smartBlogManagement.asx

    <td><%# getPropertyValue(Convert.ToInt32(Eval("id")), "smartBlogName")%></td>
    <td><%# getPropertyValue(Convert.ToInt32(Eval("id")), "smartBlogComment")%></td>
    <<td><%# getPost(Convert.ToInt32(Eval("id"))).GetProperty("smartBlogTitle").Value %></td>
    

    Fixes:

    SmartListTags.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Web.Mvc.Html;
    @using Umbraco.Web;
    @using Umbraco.Core.Models;
    @{
        // Get this blogs root, does not use an id because there may be more thanone blog
        IPublishedContent objBlogRoot = Model.Content.AncestorOrSelf("SmartBlogBlog");
    
        // Get the posts in this blog
        IEnumerable<IPublishedContent> colPosts = objBlogRoot.Descendants("SmartBlogPost");
        // Create the tag dictionary
        Dictionary<String, Int32> colTagList = new Dictionary<String, Int32>();
    
        // Loop through all the posts then loop through their tags to add to the tag dictionary
        //foreach (IPublishedContent objPost in colPosts.Where(x => !String.IsNullOrEmpty(x.GetPropertyValue<String>("smartBlogTags"))))
        foreach (IPublishedContent objPost in colPosts.Where(x => !String.IsNullOrEmpty(x.GetPropertyValue<String>("smartBlogTags"))))
        {
            foreach (String strTag in (String[])objPost.GetPropertyValue("smartBlogTags"))
            {
                if (!String.IsNullOrEmpty(strTag))
                {
                    if (colTagList.ContainsKey(strTag))
                    {
                        colTagList[strTag]++;
                    }
                    else
                    {
                        colTagList.Add(strTag, 1);
                    }
                }
            }
        }
    
        <span class="smartSubTitle">Tags</span><br />
    
        // Loop through the tag dictionary showing most used first
        <div class="smartRightLowSectionContainer">
            @foreach (KeyValuePair<String, Int32> objTag in colTagList.OrderByDescending(x => x.Value))
            {
                //Deal with the tag
                <a class="smartTag tag-@objTag.Value" href="@Umbraco.NiceUrl(objBlogRoot.Id)?tag=@objTag.Key">
                    @objTag.Key
                </a><span style="color: #666;">&nbsp;&#40;@objTag.Value&#41;</span><br />
            }
        </div>
    }
    

    SmartListCategories.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Web.Mvc.Html;
    @using Umbraco.Web;
    @{
        // Get this blogs root, does not use an id because there may be more thanone blog
        IPublishedContent objBlogRoot = Model.Content.AncestorOrSelf("SmartBlogBlog");
    
        // Get the posts in this blog
        IEnumerable<IPublishedContent> colPosts = objBlogRoot.Descendants("SmartBlogPost").OrderBy("updateDate");
    
        // Create the tag dictionary
        Dictionary<String, Int32> colCategories = new Dictionary<String, Int32>();
    
        // Loop through all the posts then loop through their tags to add to the tag dictionary
        foreach (IPublishedContent objPost in colPosts)
        {
            foreach (var strCategory in objPost.GetPropertyValue<IEnumerable<string>>("smartBlogCategory"))
            {
                if (colCategories.ContainsKey(strCategory))
                {
                    colCategories[strCategory]++;
                }
                else
                {
                    colCategories.Add(strCategory, 1);
                }
            }
        }
    
        <span class="smartSubTitle smartTopBorder">Categories</span><br />
    
        // Loop through the tag dictionary
        foreach (KeyValuePair<string, int> objCategory in colCategories)
        {
            //Deal with the tag
            <a class="smartCategory" href="@Umbraco.NiceUrl(objBlogRoot.Id)?category=@objCategory.Key">@objCategory.Key</a><br />
        }
    
    }
    
  • MikeeyG 1 post 71 karma points
    Feb 13, 2019 @ 16:18
    MikeeyG
    0

    Hi im experiencing the same issue. I've copied your code but it hasn't worked for me any other ideas?

    Thanks

  • Mike Chambers 614 posts 1171 karma points c-trib
    Sep 13, 2019 @ 10:44
    Mike Chambers
    0

    I ran into this too.. Seems to be that it's an issue with dashboard get results returns unpublished nodes. However the getPropertyValue uses the IpublishedContent cache, so only published nodes. Hence an error if unpublished node is in the result set.

Please Sign in or register to post replies

Write your reply to:

Draft