Issue with using an if statment to conditionally display a header in a template
In my template I'm trying to check if my header content item has a value. If it has a value I want it to be displayed as an h2, if it does not have a value I don't want to display it. I tried the code below but it does not work. What would be the proper syntax for this?
var leftHeader = item.Value<IPublishedContent>("interiortLeftHeader");
@if(leftHeader != ""))
{ <h2>@item.Value("interiortLeftHeader")</h2> }
Issue with using an if statment to conditionally display a header in a template
In my template I'm trying to check if my header content item has a value. If it has a value I want it to be displayed as an h2, if it does not have a value I don't want to display it. I tried the code below but it does not work. What would be the proper syntax for this?
Thank you.
Hi Jason
It depends what type of property editor is, I'm going to assume it is a textstring as tgat would be normal for a header... Then
@if (item. HasValue("interiorLeftHeader")) { <h2>@(item.Value<string>("interiortLeftHeader")) </h2> }
Would I think be what you are after?
Regards
Marc
That worked perfectly!
Thank you!
That's good, because I was typing on my mobile and it took ages to escape the code sample with & lt; etc!
is working on a reply...