Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I am trying to check if a dynamic item is null or not.
I have used the "HasValue" as recommended in my Google searches but it does not work. Using this just make it skip this block of code
here is my code snippet. I am trying to check if linkToPage has a value.
@{ if (CurrentPage.HasValue("featuredItems")) { var featureList = CurrentPage.featuredItems.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); var featureCollection = Umbraco.Content(featureList); foreach (var item in featureCollection) { <div class="col-sm-4 col-xs-6 margin30 featured-content-block"> <div> @if (item.HasValue(@item.linkToPage)) { <a href="/@item.linkToPage/"> <div class="item-img-wrap"> <img src="@Umbraco.Media(@item.featureImage).Url" class="img-responsive" alt=""> </div> </a> } else { <div class="item-img-wrap"> <img src="@Umbraco.Media(@item.featureImage).Url" class="img-responsive" alt=""> </div> } <div class="news-desc"> <h4 style="color:white">@item.featureText</h4> </div> </div> </div> } } }
I found the answer.. for anyone else having this issue.. you need to write the alias name of the property so my code from above has changed to this:
@if (@item.HasValue("linkToPage"))
So it is if item has a value in there called link to page then do whatever is within the block of code.
Thanks
Nav
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
check dynamic item
Hi,
I am trying to check if a dynamic item is null or not.
I have used the "HasValue" as recommended in my Google searches but it does not work. Using this just make it skip this block of code
here is my code snippet. I am trying to check if linkToPage has a value.
I found the answer.. for anyone else having this issue.. you need to write the alias name of the property so my code from above has changed to this:
So it is if item has a value in there called link to page then do whatever is within the block of code.
Thanks
Nav
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.