Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Reimer 30 posts 120 karma points
    Dec 09, 2013 @ 14:52
    Brian Reimer
    0

    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>

                    <div class="prod_holder"> <a href="#"> <img src=[image from Media Picker] alt=""</a>

                      <h3>@items.underskrift </h3>

                    </div>

                    <span class="pricetag">@items.overtekst</span> 

    </li>

      }

    The code loops ok - but I don't get the image.   

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 15:06
    Jeavon Leopold
    0

    Hi Brian,

    Something like this (substitute "mainImage" for your media picker property alias):

    @{    
        var karo = CurrentPage.karoRep.First().karoItem.Where("Visible");
    
        foreach (var item in karo)
        {
            <li>    
                <div class="prod_holder">
                    @if (item.HasValue("mainImage"))
                    {
                        var dynamicMediaItem = Umbraco.Media(item.mainImage);
                        <a href="#"> <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
                    }
                    <h3>@item.underskrift </h3>    
                </div>    
                <span class="pricetag">@item.overtekst</span>     
            </li>
        }
    }
    

    Reference for media picker documentation

    Jeavon

  • Brian Reimer 30 posts 120 karma points
    Dec 09, 2013 @ 15:31
    Brian Reimer
    0

    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. 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 15:36
    Jeavon Leopold
    0

    Ok, I think the snippet is ok, did you replace both instances of "mainImage" with your media pickers property alias?

    var dynamicMediaItem = Umbraco.Media(item.yourPropertyAlias);
    
  • Brian Reimer 30 posts 120 karma points
    Dec 09, 2013 @ 15:40
    Brian Reimer
    0

    Yep...

    if (item.HasValue("testBillede"))

                    {

                        var dynamicMediaItem = Umbraco.Media(item.testBillede);

                        <a href="#"> <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>

                    }

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 15:42
    Jeavon Leopold
    0

    Hmm, looks fine, can you post the entire contents of your partial view?

  • Brian Reimer 30 posts 120 karma points
    Dec 09, 2013 @ 15:46
    Brian Reimer
    0

    @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>

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 15:50
    Jeavon Leopold
    0

    Ah ok, just a missing @ before the if

    Complete snippet below:

    @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">
                            @if (item.HasValue("testBillede"))
                            {
    
                                var dynamicMediaItem = Umbraco.Media(item.testBillede);
                                <a href="#">
                                    <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/></a>
                           }
    
                            <h3>@item.underskrift ** @item.testBillede ** </h3>
    
                        </div>
                        <span class="pricetag">@item.overtekst</span>
                    </li>
                }
            </ul>
            <a href="#" class="previous_round">Previous</a> <a href="#" class="next_round">Next</a>
        </div>
    </div>
    
  • Brian Reimer 30 posts 120 karma points
    Dec 09, 2013 @ 15:52
    Brian Reimer
    0

    Perfekt - thanks :) !!!!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 20:42
    Jeavon Leopold
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft