Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Jun 07, 2017 @ 13:38
    Neil Hodges
    0

    Handling CheckBox List in 7.6 with new Property Value Converters

    Hi

    Still getting my head around the new value property converters. Im trying to access a CheckBox List. Using Smart Blog and adapting how it usually gets those prevalues.

    I have the following code:

    // 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").Where(x => x.IsVisible() == true);
    
    // 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)
    {
        String[] colCategoryNames;
        if (!String.IsNullOrEmpty(objPost.GetPropertyValue<String>("smartBlogCategory")))
        {
             colCategoryNames = objPost.GetPropertyValue<String>("smartBlogCategory").Split(',');
        }
        else
        {
             colCategoryNames = new String[0];
        }
    
        foreach (String strCategory in colCategoryNames)
        {
            if (colCategories.ContainsKey(strCategory))
            {
                colCategories[strCategory]++;
            }
            else
            {
                colCategories.Add(strCategory, 1);
            }
        }
    }
    

    I belive this section needs changing to access the Property Value Converter?

    String[] colCategoryNames;
            if (!String.IsNullOrEmpty(objPost.GetPropertyValue<String>("smartBlogCategory")))
            {
                 colCategoryNames = objPost.GetPropertyValue<String>("smartBlogCategory").Split(',');
            }
            else
            {
                 colCategoryNames = new String[0];
            }
    

    Unsure how to access the String array in the value? Tried casting it to a String[] but just get null value. Can someone point me in the right direction. The online documents don't outline Checkbox list.

  • Neil Hodges 338 posts 987 karma points
    Jun 07, 2017 @ 13:52
    Neil Hodges
    0

    I may have fixed this myself :)

    I changed the code to this:

    String[] colCategoryNames;
    
        if (!String.IsNullOrEmpty(objPost.GetPropertyValue<String>("smartBlogCategory")))
        {
            var ct = objPost.GetProperty("smartBlogCategory").DataValue.ToString();
    
            colCategoryNames = ct.Split(',');
        }
        else
        {
            colCategoryNames = new String[0];
        }
    

    Seems the DataValue returns the comma delimited string i need to split.

  • Jason 122 posts 637 karma points
    Jun 27, 2017 @ 18:34
    Jason
    0

    Late to the party but for this checkboxlist issue, but for 7.6+ if the EnablePropertyValueConverters option is set to true in the umbracoSetting.config then you can cast a checheckboxlist as an IEnumerable

    myIPublishConentNode.GetPropertyValue<IEnumerable<string>>("myCheckbocListPropertyAlias")
    
Please Sign in or register to post replies

Write your reply to:

Draft