VariationRoot's Document Type has a isEnabledLanguage true/false property.
In the VariationRoot's Template I do this:
// First, collect the available languages in the sitevar availableLanguages = Model.Children().ToList()
.Where(c => c.Field<string>("isEnabledLanguage") == "True")
.Select(c => c.UrlName.ToLower());
I was hoping to be able to skip the == "True" but I don't find any documentation about a more elegant way.
var availableLanguages = Model.Children().ToList()
.Where(c => c.Field<bool>("isEnabledLanguage"))
.Select(c => c.UrlName.ToLower());
However, this won't work as True/False fields save the string "True" for true values, but save an empty string for false values. And you can't convert an empty string to a boolean value. I suspect this is because of the way ASP.NET MVC stores checkbox values. But I think it's something that should be addressed by the core team, as you really want to be able to treat True/False values as true booleans.
Most elegant way to checking a bool property
Content Tree:
root
> VariationRoot
>> en-US
>> en-UK
VariationRoot's Document Type has a isEnabledLanguage true/false property.
In the VariationRoot's Template I do this:
I was hoping to be able to skip the == "True" but I don't find any documentation about a more elegant way.
What is a better, cleaner way to do this check?
Which version of Umbraco are you using? Is this 5?
I'm sorry, this is indeed Umbraco 5.
In theory you should be able to do:
However, this won't work as True/False fields save the string "True" for true values, but save an empty string for false values. And you can't convert an empty string to a boolean value. I suspect this is because of the way ASP.NET MVC stores checkbox values. But I think it's something that should be addressed by the core team, as you really want to be able to treat True/False values as true booleans.
is working on a reply...