I have a small ask, I'm using a true/false data type to show and hide a section on the page the code is below which kind of works, but the default off selection is hiding all the content rather than when the value is true then hide it, is it possible to swap around the values so:
False is show content by default
True is hide content
Checking boolean value
Hi,
I have a small ask, I'm using a true/false data type to show and hide a section on the page the code is below which kind of works, but the default off selection is hiding all the content rather than when the value is true then hide it, is it possible to swap around the values so:
False is show content by default True is hide content
Again thanks for all the Umbraco support :-)
Hi Nick
Do you mean like this
eg you just want to reverse the logic here??
or are you hitting a common pitfall where you have added the Checkbox to existing published pages?
If so it is the absence of the checkbox in the published cache that is being transformed as 'false' rather than any default value.
if this is the case then you can check whether the property exists in the cache via:
Model.HasProperty("hideAboutSection")
and then you could have
if (!Model.HasProperty("hideAboutSection") || !Model.HideAboutSection)
and it would show the section by default for all pages or if the checkbox isn't ticked to hide the section.
God it does your head in to think about 'hide' and 'not hide' so hopefully that is explained correctly way around!
regards
Marc
Brilliant!
Thanks Marc your solution worked exactly as expected.
Many thanks
is working on a reply...