Copied to clipboard

Flag this post as spam?

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


  • Dafydd Owen 33 posts 173 karma points
    May 13, 2013 @ 11:57
    Dafydd Owen
    0

    Combing media items with a property

    Hello,

     

    I was hoping to find some advice on combining two elements of an umbraco website.

    I am trying to pull through an image crop (which is working correctly) but I also want to include a textsting on the image so the user can enter in an external URL. The code below produces the image and the link but it is duplicating the list 3 times. What am I doing wrong here?

    Also, the texstring is a property on a media item.

    Thanks

     

    @{

    var children = @Model.NodeById(1302).DescendantsOrSelf();

    foreach (var item in @children) {  

    if(Model.logoCarousel.Count > 0){

    <div>

    <ul id="mycarousel" class="jcarousel-skin-tango">

    @foreach(dynamic d in Model.logoCarousel)

    {

    var link = @Model.NodeById(1302);

    <li><a href="http://@item.logoLink" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li>

    }

    </ul>

    </div>

    }

    }

    }

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2013 @ 12:15
    Fuji Kusaka
    0

    Hi, 

    Looks like you are looping your <ul id="mycarousel" class="jcarousel-skin-tango">. 

     

     

  • Dafydd Owen 33 posts 173 karma points
    May 13, 2013 @ 12:22
    Dafydd Owen
    0

    Thanks for your response.

    When I move the <ul> out of the foreach loop, it stops working. I think I am struggling to understand how to combine the two results into one foreach loop. Is that even possible? 

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2013 @ 12:29
    Fuji Kusaka
    0

    Yes it is possible. If it stops working what you could do instead when looping in your image folder container for images is to check if the textString for the image Url is empty or not.

    Something like this instead

    foreach(dynamic img in imgfolder.Children){
    var url = (img.HasValue("yourTextStringAlias"))? @img.yourTextStringAlias : ""; 
    <li><a href="@url" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li>
    }
  • Dafydd Owen 33 posts 173 karma points
    May 13, 2013 @ 13:13
    Dafydd Owen
    0

    so I have tried to impement your suggested code but it does not seem to work. This im sure is down to my error as I am completely new to razor!

    The logoCarousel is a document type set on a page, where as the url is contained on the media file. So i think when I loop inside the logoCarousel which contains a media file containing the property logoLink, it is somehow not finding the media property. 

    @{

     if(Model.logoCarousel.Count > 0){

    <ul id="mycarousel" class="jcarousel-skin-tango"> 

    @foreach(dynamic d in Model.logoCarousel)

    {

    var url = (d.HasValue("logoLink"))? @d.yourTextStringAlias : ""; 

    <li><a href="@url" title="test" target="_blank"><img src="@d.Crops.logoCrop" alt="@d.Alt" /></a></li>

    }

    </ul>

    }

    }

    and I receive an error relating to DAMP;

    'DAMP.RazorModel.DAMP_Item' does not contain a definition for 'HasValue'

     

Please Sign in or register to post replies

Write your reply to:

Draft