Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Sep 16, 2014 @ 10:50
    Keith R Hubbard
    0

    Convert Banner partial to Slimsy

    I am using the from [http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/][1]

    I would like to use slimsy or image cropper. Do i need to declare a var like Banner Images?

       @inherits 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.GetResponsiveCropUrl("cropper" , "banner"))"  />
                                </a>
                            } 
                            else
                            {
                                <img src="@(banner.GetResponsiveCropUrl("cropper" , "banner"))"  />
                            }
    
                            <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>
        }
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2014 @ 10:53
    Jeavon Leopold
    1

    Hi Keith,

    The Razor part looks fine, does it work?

    Jeavon

  • Keith R Hubbard 175 posts 403 karma points
    Sep 16, 2014 @ 10:59
    Keith R Hubbard
    0

    VS 2013 states it does not have a definition for GetResponsiveCropUrl. this is a partial

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2014 @ 11:40
    Jeavon Leopold
    1

    ah ok, could you check /Views/Web.Config in the namespaces section you should have:

    <add namespace="Slimsy"/>
    
  • Keith R Hubbard 175 posts 403 karma points
    Sep 16, 2014 @ 11:43
    Keith R Hubbard
    0

    The web.config has it

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2014 @ 11:44
    Jeavon Leopold
    1

    hmm, might just be VS confused, does it run?

  • Keith R Hubbard 175 posts 403 karma points
    Sep 16, 2014 @ 11:46
    Keith R Hubbard
    0

    Images are huge dev.outtasightwraps.com

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2014 @ 11:59
    Jeavon Leopold
    1

    Ok, so first on the VS issue, close your solution, delete the SUO file, open the solution and then build, now wait for it.

    On the images themselves, I'm guessing you've changed "banner" from upload to image cropper but you need to resave the images...?

  • Keith R Hubbard 175 posts 403 karma points
    Sep 16, 2014 @ 12:03
    Keith R Hubbard
    0

    I have done all of this with no luck.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2014 @ 20:28
    Jeavon Leopold
    1

    Ok, so your media item cropper property alias is "umbracoFile" (but named cropper) so you don't need to specify it also we need to get rid of that ToList(), and the slider should be activated on the Slimsy JS ready callback, so your code should be:

    @inherits UmbracoTemplatePage
    
    @{
        var mediaFolderId = (int)CurrentPage.BannersMediaFolder;
    }
    
    @if (mediaFolderId > 0)
    {
        var mediaFolder = Umbraco.TypedMedia(mediaFolderId);
        var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Banner");
    
        <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.GetResponsiveCropUrl("banner"))" />
                            </a>
                        } 
                        else
                        {
                            <img src="@(banner.GetResponsiveCropUrl("banner"))" />
                        }
    
                        <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">
            $(document).ready(function () {
                window.slimmage.readyCallback = function() {
                    $('#banners').carouFredSel({
                        scroll: {
                            items: 1,
                            duration: 1000
                        },
                        auto: {
                            progress: ".progress-bar"
                        }
    
                    });
                }
            });
        </script>
    }
    

    This will kinda get it working however the image needs to have a width and height set in CSS for it all to work.

    For a test you can add a width and height to the containing div e.g:

    <div class="banner" style="width:500px;height:300px">
    
  • Keith R Hubbard 175 posts 403 karma points
    Sep 17, 2014 @ 13:29
    Keith R Hubbard
    0

    Maybe I need to find a more responsive slider. this banner works but does not seem to compliment slimsy. any suggestion?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 17, 2014 @ 13:45
    Jeavon Leopold
    0

    Are you sure, it seemed ok to me. You just need to get your images being sized by CSS?

    A alternative that I know a few are using with Slimsy is bxSlider

  • Stephen Davidson 216 posts 392 karma points
    Oct 10, 2014 @ 16:50
    Stephen Davidson
    0

    Hi There, I too am using this banner and it suddenly developed a problem with the following, did you experince this?

    Server Error in '/' Application.


    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error: 

    Line 29:                     
    Line 30:                     <div class="banner-text">
    Line 31: <h2>@(banner.GetPropertyValue<string>("headline"))</h2> Line 32:                        <a href="@link.Url" class="button">@(banner.GetPropertyValue<string>("linktext")) <i class="fa fa-external-link-square"></i></a>
    Line 33:                         <p>@Html.Raw(banner.GetPropertyValue("subheadline"))</p>


    Source File: d:\home\site\wwwroot\Views\Partials\homepageManyBanners.cshtml    Line: 31 

    Stack Trace: 

    [NullReferenceException: Object reference not set to an instance of an object.]
       ASP._Page_Views_Partials_homepageManyBanners_cshtml.Execute() in d:\home\site\wwwroot\Views\Partials\homepageManyBanners.cshtml:31
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +199
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +90
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +236
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +93
       System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +277
       System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) +57
       ASP._Page_Views_umbHomePage_cshtml.Execute() in d:\home\site\wwwroot\Views\umbHomePage.cshtml:8
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +199
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +236
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +93
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +22
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +68
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2014 @ 16:58
    Jeavon Leopold
    0

    Looks like "banner" is null, do you have a check? Perhaps you could post the entire partial view?

  • Stephen Davidson 216 posts 392 karma points
    Oct 10, 2014 @ 17:03
    Stephen Davidson
    0

    Thanks!

    @inherits 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>
                            <a href="@link.Url" class="button">@(banner.GetPropertyValue<string>("linktext")) <i class="fa fa-external-link-square"></i></a>
                            <p>@Html.Raw(banner.GetPropertyValue("subheadline"))</p>
    
                        </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({
                    responsive: true,
                    scroll: {
                        items: 1,
                        duration: 1000
                    },
                    auto: {
    
                    }
    
                });
            });
        </script>
    }
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2014 @ 17:07
    Jeavon Leopold
    0

    Ah ok, probably one of the banners has been deleted, try this:

    var banners = mediaFolder.Children(x => x != null && x.DocumentTypeAlias == "Banner").ToList();
    
  • Stephen Davidson 216 posts 392 karma points
    Oct 10, 2014 @ 17:10
    Stephen Davidson
    0

    Thats the weird thing...nothing has been deleted only a new media fodler added. Tried your code and i still get the error.

  • Stephen Davidson 216 posts 392 karma points
    Oct 10, 2014 @ 17:22
    Stephen Davidson
    0

    Worked it out...my banner were allowed to link to internal pages...one of those pages had been deleted! Thanks for your input...got me thinking!

     

    S

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2014 @ 17:23
    Jeavon Leopold
    0

    Np, glad you solved it!

  • Thomas T 66 posts 227 karma points
    Mar 07, 2015 @ 10:49
    Thomas T
    0

    Hi,

       I too have the same problem. But it shows error on this line "var mediaFolder =Umbraco.TypedMedia(mediaFolderId);". How can I solve this ?

Please Sign in or register to post replies

Write your reply to:

Draft