The idea is to ensure that there is a value in there before getting the media url. But it seems no matter waht its always getting through and failing/erroring because no image is assigned to node.
Alternatively, this might (but might not in all cases) work... @if (!string.IsNullOrEmpty(CurrentPage.Image))
(and throw away the razor cheatsheet from v4 when using v5; the implementations are different. hopefully someone will whip up an equivelent cheatsheet for v5 soon)
if statement to check if property exists and has a value
Hi All,
This is my first site using Razor on V5 so relatively new to it all but reading through I thought the following would of worked
The idea is to ensure that there is a value in there before getting the media url. But it seems no matter waht its always getting through and failing/erroring because no image is assigned to node.
Any help greatly appreciated.
Thanks,
Tom
Bump... This is driving me around twist.
Try this...
@if (CurrentPage.Image != HiveId.Empty.ToString())
Alternatively, this might (but might not in all cases) work... @if (!string.IsNullOrEmpty(CurrentPage.Image))
(and throw away the razor cheatsheet from v4 when using v5; the implementations are different. hopefully someone will whip up an equivelent cheatsheet for v5 soon)
cheers,
doug.
Doug, I owe you a pint mate. That worked a treat.
I guess using the v4 cheatsheet doesn't help too :)
Thanks again,
Tom
You're welcome, Tom!
See you at CG12 in just over a month!
d.
BTW, you'll find this references helpful as you get into Razor in v5
http://our.umbraco.org/documentation/v501/Reference/Templating/DynamicModel
(note that starting with v5, @DynamicModel has been deprecated and is now @CurrentPage ... does the same thing but name makes more sense)
cheers,
doug.
is working on a reply...