Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    May 29, 2015 @ 09:15
    Tony Groome
    0

    How do I create an image slider?

    Hi All

    I haven't found a way to do this yet, is there an easy way to set up an image slider in Umbraco? I have the 16 images I need to display, it's just displaying them! I tried http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/ and couldn't get this to work at all. Surely there must be an easier way.

    Thanks.

    Tony

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 29, 2015 @ 10:38
    Dennis Aaen
    1

    Hi Tony,

    There is many ways that you can solve this task on I would try to describe some of the approaches. First approach that I think you could use is add a media picker on the document types where it should be able to have a image slider. What you then need is to loop though all the images in that folder. For the slider functionally you could use the Slick slider http://kenwheeler.github.io/slick/

    The Razor code for looping though images in a selected folder from the media section could look like this. Where the pictures is the alias of the property on the document type.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{      
    
        if (CurrentPage.HasValue("pictures")){                                         
    
            var dynamicMediaFolder = Umbraco.Media(CurrentPage.pictures);
    
             <ul>
    
                @foreach (var picture in dynamicMediaFolder.Children)
    
                {
    
                    <li>
    
                        <a href="@picture.Url">
    
                            <img src="@picture.umbracoFile" alt="@picture.Name" />
    
                        </a>
    
                    </li>
    
                }
    
            </ul>
    
        }
    
    }
    

    Another way of doing this if you want to be able to add a captions or other stuff to each slides, could be setup an repository in the same level as your home page, and under this you can create a slider container item, and under this item you can create each slide, where you can pick an image from the media section, maybe write some text to each slide as well.

    If you choose this option then you need to change the media picker on the document type to a content picker, but you can still use the slick framework.

    The last thing I think you could do is using the uskyslider package to build your imager slider. https://our.umbraco.org/projects/backoffice-extensions/uskyslider

    Hope this helps, and makes sense.

    /Dennis

  • Tony Groome 261 posts 804 karma points
    May 29, 2015 @ 13:49
    Tony Groome
    0

    Hi Dennis

    Thanks for your thoughts on this. I had a good look. The last option is out because you have to buy a jQuery plugin, I don't understand the second option at all, so I thought I would give the first option a go! I managed to get one image to display, from a folder of two, and it wouldn't slide. The image was huge too!! So I figured it might be because the Document type was a Media picker, so I changed it to a Multi Media Picker and now there's no image at all! It's time to walk away for a while and come back in a bit!

    Thanks.

    Tony

  • Martin 114 posts 313 karma points
    May 29, 2015 @ 17:50
    Martin
    1

    Hi Tony,

    I have followed the same guide http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/ and it works fine. However, I remember that there was some reference errors in the example. Make sure that the carouFredSel script file is referenced correctly i.e. the name of the referenced file (packed version or not packed) is the same as the actual file in your script folder. Also dobble check the names of you folder/doc types/properties etc. I am sure you already have but sometimes it takes 3-4 times to see it, at least for me :-)

    If you want, I could provide you with my code.

    Good luck!

    /martin

  • Tony Groome 261 posts 804 karma points
    Jun 03, 2015 @ 09:05
    Tony Groome
    0

    Hi Martin

    Thanks for that. Yes me too, I have to look, look again and leave it, come back and then I might see something missing! Some code would be great please!

     

    Thanks.

    Tony

  • Martin 114 posts 313 karma points
    Jun 04, 2015 @ 15:38
    Martin
    1

    Hi Tony, here comes some come code. I hope you have some help from it. I keep it in partial view ("Slideshow.cshtml") and call it using @Html.Partial("Slideshow", @Model.Content) where I want it in my home-template.

    Good luck! /martin

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @*inherits UmbracoTemplatePage *@
    
    @{
    var mediaFolderId = (int)CurrentPage.slideshowFolder;
    }
    
    
    @if (mediaFolderId > 0)
    {
    var mediaFolder = Umbraco.TypedMedia(mediaFolderId);
    var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Slideshow").ToList();
    
    <div id="pager"></div>  
    
    <div id="Slider">
       @foreach (var banner in banners)
       {
       var link = Umbraco.TypedContent(banner.GetPropertyValue<int>("link"));
       <div class="slide">
          @if (link != null)
          {
          <img src="@(banner.GetPropertyValue<string>("image"))"/>
    
    
          }
          else
          {
          <img src="@(banner.GetPropertyValue<string>("image"))" />
          }
    
           <a href="@link.Url">
           <div class="slideText" style="background-color:@(banner.GetPropertyValue<string>("slideTextColor"));">
             <h1>
                @(banner.GetPropertyValue<string>("headline"))
             </h1>
             @Html.Raw(banner.GetPropertyValue("text"))
              <cite>
                @(banner.GetPropertyValue<string>("author"))
             </cite> 
          </div> 
              </a>
       </div>
       }
    </div>
    <script type="text/javascript" src="/Scripts/jquery.carouFredSel-6.2.1-packed.js"></script>
    <script type="text/javascript">
    
    $(window).load(function () {
    
    $('#Slider').carouFredSel({
        responsive: true,
        pagination: "#pager",
        direction: 'up',
        scroll: {
            items: 1,
            fx : "crossfade",
            duration: 1400
            },
        auto: {
            progress: ".progress-bar"
        }
    });
    });
    </script>
    
    }
    
  • Tony Groome 261 posts 804 karma points
    Jun 09, 2015 @ 12:40
    Tony Groome
    0

    Hi Martin

    Thanks for that. All I could get it to do was show me the pictures that should be in the slider!

    I wrote it off and downloaded a new instance of Umbraco and started again with what appeared to be a simple step by step process http://24days.in/umbraco/2014/grid-macros/ This just gives me my three images displayed one on top of the other.

    Anybody else tried this?

    Thanks Tony

  • Tony Groome 261 posts 804 karma points
    Jun 09, 2015 @ 17:25
    Tony Groome
    100

    Hi Martin

    As Victor Meldrew would say "I DON'T BELIEVE IT!!!" I got http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/ to work!! All it needed was the js. I don't know how I missed that!! Wow seriously! Just don't tell anybody!

    Tony

  • Martin 114 posts 313 karma points
    Jun 11, 2015 @ 16:15
    Martin
    0

    Congrats Tony :-)

    The js can cause headache every now and then. I forgot a cookie js-file once and wondered why no cookie where created....

    //martin

  • Tony Groome 261 posts 804 karma points
    Jun 12, 2015 @ 08:38
    Tony Groome
    0

    I have just discovered something strange. After the celebrations of getting the slider to work, I went home wagging my tail! I got back to the project a day or so later and re did the slider and.....it displays all the images in the Home Page Banners folder, one above the other. So I re read and checked and re checked still the same. So I decided to set up another test instance. This time I chose the Fanoe starter kit, and the same. So this morning I had a thought and tried the green coloured starter kit and - it worked perfectly first time no bother at all. Grant you the green kit already had a Banner tab on the home document type. The plot thickens.....though I have realised I'm not completely mad!! I'll post an update when I get to the bottom of this.....

  • Ismail Ahmad 7 posts 27 karma points
    Jul 02, 2015 @ 07:30
    Ismail Ahmad
    0

    Hi Tony, ive been dealing with the same issue for the past 2 days and cant seems to get it work.. ive been using fanoe stater kit that already included in umbraco 7.2.6 and trying image slider from here http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/

    and ive been checking the banner folder name and get it called using

    @{ Html.RenderPartial("homepageManyBanners"); }
    

    or this

    @Html.Partial("Slideshow", @Model.Content)
    

    i dunno..im still confusing to how this slider gonna work??? i even cant get the image out in the homepage...

  • Tony Groome 261 posts 804 karma points
    Jul 02, 2015 @ 08:17
    Tony Groome
    0

    Hi Ismail

    I feel your pain! I couldn't get it to work in the Fanoe kit either. It did work for me in one of the other kits, and only that one! I have no idea why?! The kit I used was the one Carlos Martinez used, I picked it judging from the greenish colours in his example. I tried it in a clean empty project I was working on, and couldn't get it to work there either.

    Hope that kind of helps. It was all I could do.... I just gave up on the Fanoe and other kit example too and my project. I was trying to get it sorted for an intrantet I'm working on and I felt like I was being a nuisance! Luckily the slider wasn't an issue as I didn't get anywhere. Sorry I can't be more help.

    Tony

  • Ismail Ahmad 7 posts 27 karma points
    Jul 02, 2015 @ 08:27
    Ismail Ahmad
    0

    thank you Tony for your reply...im starting to stuck in here, maybe i'll try different kit for this slider.. By the way, what kit did you use for the Martinez slider???

    im still 2 week old using umbraco, and i dont get the greenish colour you mention before...

  • Tony Groome 261 posts 804 karma points
    Jul 02, 2015 @ 08:54
    Tony Groome
    0

    Hi Ismail

    In my 'Downloads' folder I have an unzipped instance of Umbraco, so I unzipped it and started again. When it was unzipped I opened the website as a website with WebMatrix. Then run it in a browser. Fill in the form and Customize. Then Continue. The next page has the three examples of the Umbraco kits. I used the one in the middle. When you publish it, the homepage looks like this:

    enter image description here

    If you do the Carlos Martinez way it should work, just don't forge the javascript - I did! Hope this helps. Tony

  • Ismail Ahmad 7 posts 27 karma points
    Jul 02, 2015 @ 10:04
    Ismail Ahmad
    0

    Dear Tony, oh i get it, im just using basic installation this whole time and not noticing the costumize button.... i already done it all and put the jquery.carouFredSel-6.2.1.js intead of jquery.carouFredSel-6.2.1-packed.js on the homepageManyBanners.cshtml and put this code @{ Html.RenderPartial("homepageManyBanners"); } on the homepage template...but still i cant get my image out.. did i do something wrong???

    im still optimistic to get this slider work...and thanks again for your patient..

  • Tony Groome 261 posts 804 karma points
    Jul 02, 2015 @ 15:03
    Tony Groome
    0

    Hi Ismail

    I found my old project and got around the password! I had forgotton it!

    My images live in a folder called Home Page Banners in the Media section. I also used jquery.carouFredSel-6.2.1-packed.js which lives in the Scripts folder. I have a Partial View called homepageManyBanners:

    `@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{ var mediaFolderId = (int)CurrentPage.BannersMediaFolder; }

    @if (mediaFolderId > 0) { var mediaFolder = Umbraco.TypedMedia(mediaFolderId); var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Banner").ToList();

    <div id="banner-wrapper">
        <div id="banners">
            @foreach (var banner in banners)
            {
                var link = Umbraco.TypedContent(banner.GetPropertyValue<int>("link"));
    
                <div class="banner">
                    @if (link != null)
                    {
                        <a href="@link.Url">
                            <img src="@(banner.GetPropertyValue<string>("image"))"/>
                        </a>
                    } 
                    else
                    {
                        <img src="@(banner.GetPropertyValue<string>("image"))"  />
                    }
    
                    <div class="banner-text">
                        <h2>@(banner.GetPropertyValue<string>("headline"))</h2>
                        @Html.Raw(banner.GetPropertyValue("bannertext"))
                            <cite>@(banner.GetPropertyValue<string>("author"))</cite>
                    </div>
                </div>
            }
        </div>
    </div>
    <div class="progress-bar"></div>
    <script type="text/javascript" src="/scripts/jquery.carouFredSel-6.2.1-packed.js"></script>
    
    <script type="text/javascript">
        $(window).load(function () {
            $('#banners').carouFredSel({
                scroll: {
                    items: 1,
                    duration: 1000
                },
                auto: {
                    progress: ".progress-bar"
                }
    
            });
        });
    </script>
    

    }

    ` Then in the homepage:

    @{ Html.RenderPartial("homepageManyBanners"); }
    

    I could only get this to work in the one kit.

    Hope this helps. Tony

  • AJS 31 posts 212 karma points
    Apr 25, 2016 @ 19:20
    AJS
    0

    Hi there,

    I followed the tutorial exactly and took into account the comment thread here, but I keep getting

    Cannot convert type 'string' to 'int' 
    

    on the initial

    @{ var mediaFolderId = (int)CurrentPage.BannersMediaFolder; }
    

    Does anyone have any suggestions?

    Thanks,

    Amanda

  • Martin 114 posts 313 karma points
    Apr 26, 2016 @ 10:24
    Martin
    0

    Hi,

    One idea that might solve it:

    Your BannersMediaFolder should be of type Media Picker, i.e., you pick a media folder and reference the picker instead of the actual folder itself.

    //martin

  • AJS 31 posts 212 karma points
    Apr 26, 2016 @ 15:23
    AJS
    0

    Thanks so much for responding, Martin.

    I think I've set the bannersMediaFolder to be a media picker....

    enter image description here

    So, I'm not entirely sure...

  • Martin 114 posts 313 karma points
    Apr 26, 2016 @ 16:54
    Martin
    0

    Hi,

    I see that you have a multiple media picker. Try change it to "just" a Media picker.

  • AJS 31 posts 212 karma points
    Apr 26, 2016 @ 17:23
    AJS
    0

    Awesome. Thanks so much. The page is not giving me an error anymore, but it is now not rendering the pictures.

    It renders the banners div, but none of the individual banners and text

    enter image description here

    which makes me think that the

    var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Banner").ToList();
    

    is not working...

  • Martin 114 posts 313 karma points
    Apr 27, 2016 @ 09:51
    Martin
    0

    Check the .js file so that you are referencing the correct one. If I remember correctly, there is also a packed version and the referenced name may differ.

  • AJS 31 posts 212 karma points
    May 02, 2016 @ 22:02
    AJS
    0

    Thanks so much for the suggestion. Unfortunately, it does look like I'm referencing the correct JS file. Any other ideas?

    enter image description here

  • Martin 114 posts 313 karma points
    May 03, 2016 @ 12:50
    Martin
    0

    Hi,

    I had a problem with rendering at first but that was due to css-styling of parent div which prevented the slideshow behave correctly. I have attach my code below which work fine. Maybe you cound test it. OBS!! Make sure to change my "#Slider" to the name you are using.

    Also, if you use Firefox you can use the inspector as well as 3D view to check if the div´s in fact are generated (otherwise there is a problem with you code in umbraco). And check if you are using z-index so that the picture and text aren´t hidden in the back.

    <script type="text/javascript">
    
    $(window).load(function () {
    
    $('#Slider').carouFredSel({
        responsive: true,
        pagination: "#pager",
        direction: 'up',
        scroll: {
            items: 1,
            fx : "crossfade",
            easing : "swing",
            duration: 1400
            },
        auto: {
            progress: ".progress-bar"
        }
    });
    });
    </script>
    
Please Sign in or register to post replies

Write your reply to:

Draft