I've gotten in the habit of checking my umbraco true/false properties as follows:
if (mediaFolder.myProperty.GetType() == typeof(bool) && (bool)mediaFolder.myProperty) { /* checkbox is checked! */ }
This is because sometimes there is an unknown state on the property (null or missing) you might want to assign your own default to (i.e., treat a null as either a true or a false? just change the logic/comparison to reverse.) So, sometimes umbraco gives you this as a proper bool, sometimes not. The code above lets me be sure I actually have a bool when I need one.
There is also a library helper if you are just looking to output a different string based on this,
@Library.If(mediaFolder.myProperty, "yay! checked!", "boooo, not checked")
Get value of property on Media Folder?
I've added a custom true/false property to the Media Folder data type "myproperty", and am struggling to work out how to access it's value.
I've gotten in the habit of checking my umbraco true/false properties as follows:
if (mediaFolder.myProperty.GetType() == typeof(bool) && (bool)mediaFolder.myProperty) { /* checkbox is checked! */ }
This is because sometimes there is an unknown state on the property (null or missing) you might want to assign your own default to (i.e., treat a null as either a true or a false? just change the logic/comparison to reverse.) So, sometimes umbraco gives you this as a proper bool, sometimes not. The code above lets me be sure I actually have a bool when I need one.
There is also a library helper if you are just looking to output a different string based on this,
@Library.If(mediaFolder.myProperty, "yay! checked!", "boooo, not checked")
Best of luck!
Ah thanks Funka, keep forgetting the bool check :/
Do you know of another method of getting a media folder id by name, other than using ucomponents' uquery? ( uQuery.GetMediaByName )
is working on a reply...