Copied to clipboard

Flag this post as spam?

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


  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 22, 2012 @ 16:10
    Dan Diplo
    0

    True/False sometimes comes back as "0" or "1" rather than bool

    This is a really weird problem. I have a master DocType called ContentMaster that has a True/False property on it called hideFromSitemap. I then have a number of DocTypes that inherit from ContentMaster, such as Article, Folder, ContactPage etc. Obviously all of these DocTypes also have the hideFromSitemap True/False property on them.

    I am then listing all the pages in the site and checking outputing botht he value and type of hideFromSitemap.

    What I find is something like this:

    • Gallery  False System.Boolean
    • Photos  False System.Boolean
    • Demo Gallery  False System.Boolean
    • Footer  1 System.String
    • Another Gallery  True System.Boolean
    • Videos  False System.Boolean
    • Village Videos  False System.Boolean
    • The Gardens  False System.Boolean
    • About Us  False System.Boolean
    • FAQ  True System.Boolean

    Note the page called Footer. This is returning "1" and is of type String whereas every other node is returning as a proper boolean. Remember, the Footer page is based on a DocType that inherits from the same ContentMaster DocType that has hideFromSitemap defined on it as a True/False. There is no difference at all. Doesn't make sense!

    I've tried re-publishing the page, re-saving the doctypes but it makes no difference, it still comes back as a String. I've checked the Raw XML and the XML is identical for all hideFromSitemap properties regardless of DocType eg.

    <hideFromSitemap>0</hideFromSitemap>

    or

    <hideFromSitemap>1</hideFromSitemap>

    So why is it coming back as a string and not a bool for the Folder DocType ????

  • Douglas Ludlow 210 posts 366 karma points
    Jun 22, 2012 @ 16:29
    Douglas Ludlow
    0

    Could you post the razor you use to list the properties?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 22, 2012 @ 17:13
    Dan Diplo
    0

    This is the entire script. It generates a Sitemap:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    
    @{
        DynamicNode root = Model.AncestorOrSelf();
        int maxLevel = 3;
    }
    
    <ul class="sitemap">
        <li><a href="@root.Url">@root.Name</a>
            @recurseNodes(root, maxLevel)
        </li>
    </ul>
    
    
    @helper recurseNodes(dynamic node, int maxLevel)
    {
        <ul>
            @foreach (dynamic item in node.Children.Where("template > 0"))
            {
                <li><a href="@item.Url">@item.Name</a> @item.hideFromSitemap @item.hideFromSitemap.GetType()
                    @if (item.Level <= maxLevel && item.Children.Count() > 0)
                    {
                        @recurseNodes(item, maxLevel);
                    }
                </li>
            }
        </ul>
    }

     

    Note: What I wanted in my @foreach was to do this:

    @foreach (dynamic item in node.Children.Where("!hideFromSitemap && template > 0"))

    But now I have to use this work-around:

    @foreach (dynamic item in node.Children.Where("(hideFromSitemap.ToString() == \"1\" || hideFromSitemap.ToString() == \"False\") && template > 0"))
  • Adin 11 posts 31 karma points
    Apr 27, 2013 @ 19:12
    Adin
    0

    I have the same problem. Some nodes have 1 and 0 and others have True/False.

    They all inherit this property from parent document type.

    Umbraco version is 4.11.6

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 27, 2013 @ 21:25
    Dan Diplo
    0

    Wow, still doing this in 4.11.6 ? I'd report it as a bug, but I've not found any way to reproduce this. Be interesting to see if there's any reason why this might happen.

  • Adin 11 posts 31 karma points
    Apr 29, 2013 @ 01:10
    Adin
    0

    I solved my problem by making helper function which tries to parse it as bool and integer. I should probably post is as a problem.

  • Matt Taylor 873 posts 2086 karma points
    Jun 01, 2013 @ 17:21
    Matt Taylor
    0

    This is still a problem in v6.0.5.

    I'm having to use:

    var items = node.Children.Where("umbracoSitemapHide.ToString() == \"0\" || umbracoSitemapHide.ToString() == \"False\"").Where("Level <= " + maxLevelForSitemap);
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 01, 2013 @ 21:26
    Dan Diplo
    0

    Given this is still happening I've reported it as an issue. Please vote it up!

    http://issues.umbraco.org/issue/U4-2307

Please Sign in or register to post replies

Write your reply to:

Draft