Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Jun 16, 2015 @ 20:46
    Steve
    0

    Call the name of an Image in the media Library

    I have a lightbox using the jquery colorBox plugin and a Razor to pull in the images from the Media Library, but I don't know how to access the name of the image properly, I guess, because the lightbox isn't displaying the name in the "title" area for the slide. I am using title="@slide.name" in my loop below to get the name. Is't that correct? Here is my Razor, any suggestions?

        @{ 
    
        var trans = string.IsNullOrEmpty(Parameter.transition) ? @Html.Raw("transition:'elastic'") : @Html.Raw("transition:'@Parameter.transition'");
        var slideshow = (Parameter.slideShow == "1") ?  @Html.Raw("slideshow:true") : @Html.Raw("slideshow:false");
    
        }
       <script>    
       $(document).ready(function() {
            var $gallery = $('a.slideGroup').colorbox({rel:'slideGroup',@trans, @slideshow, opacity:"0.5", title:' '});
    
            $("a#openGallery").click(function(e){
                e.preventDefault();
                $gallery.eq(0).click();
            });
        }); 
    </script>   
    
    @{
    
    
        if (!String.IsNullOrEmpty(Parameter.slideFolder)){
    
            var slideFolder = Library.MediaById(Parameter.slideFolder);
            var width = string.IsNullOrEmpty(Parameter.slideWidth) ? "350" : Parameter.slideWidth;
            var height = string.IsNullOrEmpty(Parameter.slideHeight) ? "100%" : Parameter.slideHeight;
    
        <ul class="cboxGallery">
                @foreach(var slide in slideFolder.Children) {
                <li>
                    <a class="slideGroup" href="@slide.umbracoFile" ><img src="/ImageGen.ashx?image=/media/1319203/slide-controls-overlay.png&width=@width&height=@height" /><img src="/[email protected]&width=@width&height=@height" title="@slide.name" /></a>  
                </li>
                }
        </ul>
                }
    }
    
  • Ste 14 posts 35 karma points
    Jun 25, 2015 @ 13:07
    Ste
    0

    Hey Steve,

    It seems your code has been mangled a bit, could you post again with all the code indented by at least 1 tab for the Markdown parser to get it right? :) Here's my guess:

    @{ 
    
    var trans = string.IsNullOrEmpty(Parameter.transition) ? @Html.Raw("transition:'elastic'") : @Html.Raw("transition:'@Parameter.transition'");
    var slideshow = (Parameter.slideShow == "1") ?  @Html.Raw("slideshow:true") : @Html.Raw("slideshow:false");
    
    }
    
    @{
    if (!String.IsNullOrEmpty(Parameter.slideFolder)){
    
        var slideFolder = Library.MediaById(Parameter.slideFolder);
    
        var width = string.IsNullOrEmpty(Parameter.slideWidth) ? "350" : Parameter.slideWidth;
        var height = string.IsNullOrEmpty(Parameter.slideHeight) ? "100%" : Parameter.slideHeight;
    
        <ul class="cboxGallery">
            @foreach(var slide in slideFolder.Children)
            {
            <li>
                <a class="slideGroup" href="@slide.umbracoFile">
                    <img src="/ImageGen.ashx?image=/media/1319203/slide-controls-overlay.png&width=@width&height=@height" />
                    <img src="/[email protected]&width=@width&height=@height" title="@slide.name" />
                </a>
            </li>
            }
        </ul>
    
    }
    }
    

    Is this a PartialViewMacroPage? I'm not familiar with the older Library API but it looks like you're roughly right... have you tried @slide.Name (capital N) instead of @slide.name?

    Cheers :)

  • Steve 472 posts 1216 karma points
    Jun 25, 2015 @ 13:18
    Steve
    100

    I am sorry Steve, I just figured this out earlier. I needed to add this line of code for when the .colorbox is called:

    title: function() { return '' + $(this).attr('title') + ''; }
    

    Then, you are correct, I needed <a title="@slide.name"> when I loop. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft