Cool, one warning, in Umbraco v7.0.0 if the media item selected in the picker is ever deleted you will get a YSOD on your page, this should be fixed in Umbraco v7.0.1. There is a workaround for v7 shown here or just make sure you upgrade to v7.0.1 when available.
image from Media Picker
Have a Media Picker on my document type: karoItem
Alias: testBillede
How du i get the image in this bit of code?
@{var karo = CurrentPage.karoRep.First().karoItem.Where("Visible");}
@foreach (var items in karo)
{
<li>
<h3>@items.underskrift </h3>
</div>
<span class="pricetag">@items.overtekst</span>
</li>
}
The code loops ok - but I don't get the image.
Hi Brian,
Something like this (substitute "mainImage" for your media picker property alias):
Reference for media picker documentation
Jeavon
Hmmm - CS0103: The name 'dynamicMediaItem' does not exist in the current context ???
It's a partial view on UM7 - if that has anything to say.
Ok, I think the snippet is ok, did you replace both instances of "mainImage" with your media pickers property alias?
Yep...
if (item.HasValue("testBillede"))
{
var dynamicMediaItem = Umbraco.Media(item.testBillede);
<a href="#"> <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
}
Hmm, looks fine, can you post the entire contents of your partial view?
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<div class="box featured-box">
<h2 class="heading-title"><span>@Umbraco.Field("vidsteDuOverskrift")</span></h2>
<div class="box-content">
<ul id="myRoundabout">
@{var karo = CurrentPage.karoRep.First().karoItem.Where("Visible");}
@foreach (var item in karo)
{
<li>
<div class="prod_holder">
<a href="#">
<img src="" alt=""/></a>
if (item.HasValue("testBillede"))
{
var dynamicMediaItem = Umbraco.Media(item.testBillede);
<a href="#"> <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
}
<h3>@items.underskrift ** @items.testBillede ** </h3>
</div>
<span class="pricetag">@items.overtekst</span>
</li>
}
</ul>
<a href="#" class="previous_round">Previous</a> <a href="#" class="next_round">Next</a> </div>
</div>
Ah ok, just a missing @ before the if
Complete snippet below:
Perfekt - thanks :) !!!!
Cool, one warning, in Umbraco v7.0.0 if the media item selected in the picker is ever deleted you will get a YSOD on your page, this should be fixed in Umbraco v7.0.1. There is a workaround for v7 shown here or just make sure you upgrade to v7.0.1 when available.
is working on a reply...