Copied to clipboard

Flag this post as spam?

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


  • lucuma 261 posts 563 karma points
    Feb 04, 2013 @ 20:58
    lucuma
    0

    Dynamic Media Children Properties

    I'm having trouble looping over a media folder and getting access to some custom properties that were added to the Image document type (media section).  In my example below, no matter what I do, image.externalUrl and image.internalUrl are always empty. How does one work with custom properties?

    Screenshot of the Media type: http://screencast.com/t/DD2u7uq4X3Y

    Razor (the images display, I can't pull the URL property values):

    @foreach (dynamic image in media.Children.Where("Visible"))
    {   
      string url = string.Empty;
      if (image.HasProperty("externalUrl") && !String.IsNullOrEmpty(image.externalUrl)) {
        url = image.externalUrl;    
       } else if (image.HasProperty("internalUrl") && !String.IsNullOrEmpty(image.internalUrl)) {
       var node = new DynamicNode(image.internalUrl);   
       url = node.NiceUrl; 
       }
                            <li>
                                <a href="@url">
                                    <img src="@image.umbracoFile" alt="@image.Name"  />
                                </a>
                            </li>
    }
  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Feb 05, 2013 @ 12:27
    Jeroen Breuer
    1

    I think this should work. What happens if you try to fetch the properties with the GetProperty("") method?

    Jeroen

  • lucuma 261 posts 563 karma points
    Feb 05, 2013 @ 14:20
    lucuma
    0

    It doesn't work with GetProperty either.  It is a 4.11.3 site.

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Feb 05, 2013 @ 14:46
    Jeroen Breuer
    0

    Not sure what is the problem. What does the xml looks like when you use library.GetMedia(id, false)? 

    As an alternative you could have a look at the DAMP gallery. The example on page 2 also loops through all the children and on page 3 you see how extra properties can be fetched.

    Jeroen

  • lucuma 261 posts 563 karma points
    Feb 05, 2013 @ 15:21
    lucuma
    0

    I believe it is a cache issue. I'm not only not able to pull these properties but other media items that were long deleted are still showing up... Is there a way to clear the umbraco MEDIA cache?

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Feb 05, 2013 @ 15:22
  • lucuma 261 posts 563 karma points
    Feb 05, 2013 @ 15:32
    lucuma
    0

    I did that.. The issue might be a cache issue on the macro although I don't recall ever having that problem prior.   It was set to Cache duration: 0 and Cache by Page: Yes.. 

  • Simon steed 378 posts 700 karma points
    Apr 15, 2013 @ 17:40
    Simon steed
    0

    I've got the same problem on 4.11.4 - added property to a media item (pdf in this case), does not display or even show as a valid property via razor. Any other fixes around for this?

  • Simon steed 378 posts 700 karma points
    Apr 15, 2013 @ 18:00
    Simon steed
    0

    OK upgraded to 4.11.6 and it fixes the bug :-)

  • 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.

Please Sign in or register to post replies