I thought this would be "simple"... Being new to Razor/Umbraco 7, I am looking at the Umbraco Razor Cheatsheet (ver. 6?) and trying to make sense of it all... but alas...
On my frontpage I would like to have a div show if a property from my frontpage doc type has a value:
@{
var getInfo = Model.Content.GetPropertyValue("frontpageInfo");
if (getInfo != null )
{
<div class="container" style="color: #fff; background: #f00;">
@getInfo <p>read more here...</p>
</div>
}
}
The div shows no matter if property has value or not... What am I missing?
Yes, you can also cast to other types like <int>, <float>, <decimal>, <DateTime> etc. and choose the ideal type depending on the datatype you are using.
Simple show/hide if property has value
I thought this would be "simple"... Being new to Razor/Umbraco 7, I am looking at the Umbraco Razor Cheatsheet (ver. 6?) and trying to make sense of it all... but alas...
On my frontpage I would like to have a div show if a property from my frontpage doc type has a value:
The div shows no matter if property has value or not... What am I missing?
Hi and welcome :)
Did you debug and check the value after GetPropertyValue? I think that your variable will have an empty string set'ed by GetPropertyValue.
Do the compare like: !String.IsNullOrWhiteSpace([your_variable])
:)
Hi Bent
If you use the checkbox (true/false) property editor, the property will most likely always contains a value (0 or 1 in the published xml cache).
You can cast the property to a boolean and then compare against true or false, e.g.
or if it is a string property cast the property as a string.
/Bjarne
Ok great!... That was a solution...
So is ther also
<int>, <float>
etc?Cheers!
/Bent
Yes, you can also cast to other types like
<int>
,<float>
,<decimal>
,<DateTime>
etc. and choose the ideal type depending on the datatype you are using./Bjarne
is working on a reply...