I am currently trying to build a Macro for displaying of items with an Image, Links and Text. I have all items working aside from if the pageThumbnail is empty. The entire macro breaks at this point.
If I remove the dynamic media and the image (and surronding if) the Macro works. How can I target the media call to see if it's blank, so it doesn't crash the macro? Everything I've tried has only caused render failures or errors stating "variable media not defined."
The code in question is below:
@foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
{
dynamic media = new DynamicMedia(@item.pageThumbnail);
<div class="news-list" style="margin-bottom:10px; clear:both;">
<h2><a href="@item.Url">@item.Name</a></h2>
@if ( media.UmbracoFile != "" ) {
<img class="float-lmr" src="/imagegen.ashx?width=100&[email protected]" title="@item.Name" alt="@item.Name" />
}
<p>@item.pageSummary</p>
<p><a href="@item.Url" title="Read more about @item.Name">Read more about @item.Name</a></p>
</div>
}
Don't know if you're using DAMP for the Image Picker, but you could try the DAMP Razor Model. It has a Count and Any property to see if there are media items.
Using DynamicMedia for Image Picker
I am currently trying to build a Macro for displaying of items with an Image, Links and Text. I have all items working aside from if the pageThumbnail is empty. The entire macro breaks at this point.
If I remove the dynamic media and the image (and surronding if) the Macro works. How can I target the media call to see if it's blank, so it doesn't crash the macro? Everything I've tried has only caused render failures or errors stating "variable media not defined."
The code in question is below:
think you can use
if (media.UmbracoFile != typeof(DynamicNull))
Don't know if you're using DAMP for the Image Picker, but you could try the DAMP Razor Model. It has a Count and Any property to see if there are media items.
Jeroen
Okay, for the moment I have it working. I completely scrapped the idea of the "dynamicMedia" property.
@Mike - I couldn't get your option to work and @Jeroen we aren't using DAMP to my knowledge.
is working on a reply...