I'm hoping this isn't too silly a question - but I have a media upload field, and I'm not sure how to show the image within my cshtml macro script... I can return an id, but not the image. Hoping someone can take a look at my snippet below and point me in the right direction. I'm using Umbraco 7. Thanks!!
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){
<div class="news-listing">
<div class="row">
<div class="col-md-3">
<!-- IMAGE (@item.icImage) SHOULD SHOW IF mediaType is news -->
Image
</div>
<div class="col-md-9">
<h2><a href="@item.Url">@item.icTitle</a></h2>
<span class="news-date">Posted In: @item.mediaType</span>
@item.icIntro
<p><a href="@item.Url">Read more</a></p>
</div>
</div>
</div>
}
Thanks for the response! I'm using the Media Picker - however when I tried to use the snippet you suggested, I get an 'Error loading MacroEngine script'. Any ideas?
You are welcome, could you please mark the question as solve, as you can see you have a green tick on each post, and to mark the question as solve you need to click on green tick for the post that solve your issue.
It´s a good thing to do, so other people that come across this post can see what works for you.
Show Image From ID
Hi!
I'm hoping this isn't too silly a question - but I have a media upload field, and I'm not sure how to show the image within my cshtml macro script... I can return an id, but not the image. Hoping someone can take a look at my snippet below and point me in the right direction. I'm using Umbraco 7. Thanks!!
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){ <div class="news-listing"> <div class="row"> <div class="col-md-3"> <!-- IMAGE (@item.icImage) SHOULD SHOW IF mediaType is news --> Image </div> <div class="col-md-9"> <h2><a href="@item.Url">@item.icTitle</a></h2> <span class="news-date">Posted In: @item.mediaType</span> @item.icIntro <p><a href="@item.Url">Read more</a></p> </div> </div> </div> }Hi Dan,
What if you do something like this will you get the image then.
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){<div class="news-listing">
<div class="row">
<div class="col-md-3">
@{
var dynamicMediaItem = Umbraco.Media(item.icImage);
}
<img src="@dynamicMediaItem.Url" alt="@dynamicMediaItem.Name"/>
</div>
<div class="col-md-9">
<h2><a href="@item.Url">@item.icTitle</a></h2>
<span class="news-date">Posted In: @item.mediaType</span>
@item.icIntro
<p><a href="@item.Url">Read more</a></p>
</div>
</div>
</div>
}
In my example I assume that you are using the Built-in media picker property editor: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors/Media-Picker
Hope this helps,
/Dennis
Hi Dennis,
Thanks for the response! I'm using the Media Picker - however when I tried to use the snippet you suggested, I get an 'Error loading MacroEngine script'. Any ideas?
Hi Dan,
I think I know why you are getting the error, the snippet is for MVC and you are using the old DynamicNode Razor try this instead.
@foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize)){
<div class="news-listing">
<div class="row">
<div class="col-md-3">
@{
var dynamicMediaItem = Library.MediaById(item.icImage);
}
<img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
</div>
<div class="col-md-9">
<h2><a href="@item.Url">@item.icTitle</a></h2>
<span class="news-date">Posted In: @item.mediaType</span>
@item.icIntro
<p><a href="@item.Url">Read more</a></p>
</div>
</div>
</div>
}
Hope this helps,
/Dennis
Aha - this works perfectly! Thanks so much!!
Hi Dan,
You are welcome, could you please mark the question as solve, as you can see you have a green tick on each post, and to mark the question as solve you need to click on green tick for the post that solve your issue.
It´s a good thing to do, so other people that come across this post can see what works for you.
/Dennis
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.