Copied to clipboard

Flag this post as spam?

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


  • Rob Church 6 posts 51 karma points
    Mar 10, 2014 @ 16:07
    Rob Church
    1

    No translations, empty property causes an error in PropertyTranslation.cshtml

    I'm just getting started with Polyglot for a (mostly) 1:1 multi-lingual website.

    If I come across a page where there are no translations set up (perhaps it's new?) but a property is empty, then I get an error in the macro. I think that's because the final fallback (line 48) calls ToString() on a null reference.

    if (page.HasProperty(Parameter.Property) && !string.IsNullOrEmpty((page.GetPropertyValue(Parameter.Property).ToString())))
        {
            @Html.Raw(Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(page.GetPropertyValue(Parameter.Property).ToString()))
        }
    

    Whereas when looking through the translated nodes, it doesn't bother (line 34):

    if (translation.HasProperty(Parameter.Property) && !string.IsNullOrEmpty(translation.GetPropertyValue(Parameter.Property)))
    {
        contentFound = true;
        @Html.Raw(Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(translation.GetPropertyValue(Parameter.Property)))
    }
    

    At least, when I remove the .ToString() on my install, then it starts working. Am I missing something?

  • dimi309 245 posts 579 karma points
    Mar 11, 2014 @ 19:08
    dimi309
    0

    Hi Rob,

    Thanks for reporting this. I think you've just spotted a bug! :)

    I don't know why this did not cause a problem in the past. Are you using Umbraco 7 by any chance? Maybe the previous versions were always returning an empty string and not a null value, even when there was no value in a given field.

    I would suggest that you keep your correction, and I will also add it to the next release. Just to be on the safe side though, I would also add a check to see if the .ToString() value is an empty string, even if the property is not null.

    Best regards,

    Dimitri

  • dimi309 245 posts 579 karma points
    Mar 11, 2014 @ 20:19
    dimi309
    100

    Rob, I have just released v2.01 of the package, with you correction. Let me know if you have spotted this error in Umbraco v6 and not in v7 though. You can ignore my comment about checking the value returned from .ToString() to see if it's empty. It isn't necessary.

    Thanks again!

    Dimitri

  • Rob Church 6 posts 51 karma points
    Mar 13, 2014 @ 18:20
    Rob Church
    0

    Hi Dmitri,

    Thanks for the quick reply - yeah, this is a fresh project in Umbraco 7. Glad to have been of help.

    -Rob.

Please Sign in or register to post replies

Write your reply to:

Draft