Copied to clipboard

Flag this post as spam?

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


  • Steve Wilkinson 132 posts 211 karma points
    Jun 29, 2015 @ 09:25
    Steve Wilkinson
    0

    uLocalGovMVC "news carousel"

    I've slightly amended the news carousel (well, called it something else as I''m using it for staff updates rather than news on our intranet) - see attached file and I'm getting some very odd behavour - it may be because it's running on Umbraco v7 rather than v6, I'm not sure!

    My template code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    @* Basic Homepage news carousel, gets the last 5 items (by date) that are targeted for this type of section page (inc homepage), and displays them in a bootstrap carousel

    you would want to include things like sticky news items, auto expiry etc. *@

    @*

    Package Bug - this works but the starterKit Packaged content looses the newsLocation
                 value on import, so we are using a simpler query to prove concepts 
    
    var allNews = Umbraco.TypedContentAtXPath("//ulgNewsItem")
        .Where(x=>x.IsVisible() 
                && x.GetPropertyValue<DateTime>("articleDate") < DateTime.Now 
                && x.GetPropertyValue<string>("newsLocation").Split(new Char[]{','}, StringSplitOptions.RemoveEmptyEntries).Contains(Model.Content.Id.ToString()))
        .OrderByDescending(x=>x.GetPropertyValue<DateTime>("articleDate")).Take(5);
    
    *@
    

    @{

    var allNews = Umbraco.TypedContentAtXPath("//ulgNewsItem")
        .Where(x=>x.IsVisible() 
               && x.GetPropertyValue<DateTime>("articleDate") < DateTime.Now) 
        .OrderByDescending(x=>x.GetPropertyValue<DateTime>("articleDate")).Take(5); 
    

    }

    @if (allNews.Any()) {

    @foreach(IPublishedContent newsItem in allNews) { bool hasImage = false ; string imageUrl = "http://placehold.it/320x240" ; string imageAltText = String.Empty ; DateTime articleDate = newsItem.GetPropertyValue
    }

    The working one has 9 staff updates article dated

    21/05/2015 - 1 of 1/06/2015 - 1 of 22/06/2015 - 2 of 25/06/2015 - 2 of 26/06/2015 - 2 of

    If I set one of the 22/06/2015 ones to 26/06/2015 (well, actually anything later than 22/06/2015) then the Staff updates fail to display correctly.

    I've tracked it down to the fact that in the second scenario, no

    is set to
    therefor no newsItem.IsFirst() is true but I can't figure out why no item becomes true.

    Working html

    <div class="news" style="border-radius: 6px 6px 6px 6px;">
        <div id="carousel-news" class="carousel slide" data-ride="carousel" style="border-radius: 6px 6px 6px 6px;">
            <div class="carousel-inner">
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 25/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 25/06/2015 00:00:00;
                -->
    
            </div>
            <!-- Controls -->
            <a class="left carousel-control" href="#carousel-news" data-slide="prev">
                <span class="icon-prev"></span>
            </a>
            <a class="right carousel-control" href="#carousel-news" data-slide="next">
                <span class="icon-next"></span>
            </a>
        </div>      
    

    None working html

    <div class="news" style="border-radius: 6px 6px 6px 6px;">
        <div id="carousel-news" class="carousel slide" data-ride="carousel" style="border-radius: 6px 6px 6px 6px;">
            <div class="carousel-inner">
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 26/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 25/06/2015 00:00:00;
                -->
    
                <!-- newsItem.IsFirst(): False;
                    articleDate: 25/06/2015 00:00:00;
                -->
    
            </div>
            <!-- Controls -->
            <a class="left carousel-control" href="#carousel-news" data-slide="prev">
                <span class="icon-prev"></span>
            </a>
            <a class="right carousel-control" href="#carousel-news" data-slide="next">
                <span class="icon-next"></span>
            </a>
        </div>      
    

  • Anthony Chudley 50 posts 197 karma points
    Jun 29, 2015 @ 09:39
    Anthony Chudley
    0

    We are using a derivative of this code for our site in V7 based off the Starter Kit.

    Bit hard to work out what's going on as the forum has rather scrambled your code.

    When you say they fail to display correctly, are they not displaying at all, or displaying in a way you wouldn't expect?

  • Steve Wilkinson 132 posts 211 karma points
    Jun 29, 2015 @ 10:00
    Steve Wilkinson
    0

    Apologies for the scrambled content - I was expecting it to all display in "code" mode!

    By failing to display, the "photo", date and headline disappears in the carousel so the < > navigation is at the top and nothing can be displayed.

    Both times 5 news items are returned but in the version that works whichhas the dates 21/05/2015 - 1 of 1/06/2015 - 1 of 22/06/2015 - 2 of 25/06/2015 - 2 of 26/06/2015 - 2, class="item active" is set because one of the news items isFirst() == true

    The version which fails to display the news items correctly occurs when I set one of the 22/06/2015 ones to 26/06/2015 (well, actually anything later than 22/06/2015) .

    5 news items are returned but they are all class="item " news items isFirst() == false for each item.

  • Anthony Chudley 50 posts 197 karma points
    Jun 29, 2015 @ 10:25
    Anthony Chudley
    0

    Seems odd.

    We are using this as our selector code:

        var carouselItems = Umbraco.TypedContentAtXPath("//NewsItem")
        .Where(x=>x.IsVisible() 
               && x.GetPropertyValue<DateTime>("sortDate") < DateTime.Now) 
        .OrderByDescending(x=>x.GetPropertyValue<DateTime>("sortDate"));
    

    We aren't currently using the .IsFirst() check, but just added it in to our partial and it worked as expected. Returning true for the first item. Tried it with a .Take(x) as well and still works. So not 100% sure why it wouldn't return one as IsFirst() as true.

  • Steve Wilkinson 132 posts 211 karma points
    Jun 29, 2015 @ 10:42
    Steve Wilkinson
    0

    Using that it returns 9 news items (all the live news items) and the active one (isFirst == true) is number 6 in the list so I can see why now doing the take(5) breaks it as the item that isFirst is not in there.

    I'd made the assumption that the order was set by article date when this .OrderByDescending(x=>x.GetPropertyValue

    Thanks for the idea of where to look though, I wouldn't have figured it out without playing with that.

  • Anthony Chudley 50 posts 197 karma points
    Jun 29, 2015 @ 10:48
    Anthony Chudley
    1

    Glad I helped Steve.

Please Sign in or register to post replies

Write your reply to:

Draft