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?
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.
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.
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.Whereas when looking through the translated nodes, it doesn't bother (line 34):
At least, when I remove the
.ToString()
on my install, then it starts working. Am I missing something?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
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
Hi Dmitri,
Thanks for the quick reply - yeah, this is a fresh project in Umbraco 7. Glad to have been of help.
-Rob.
is working on a reply...