Copied to clipboard

Flag this post as spam?

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


  • Ben Evans 5 posts 85 karma points
    May 25, 2017 @ 14:14
    Ben Evans
    0

    New blog/post/MOTD notification icon next to title?

    Hi peeps!

    First post here - hoping someone can help.

    I'm currently using 7.5.3 as an intranet for a local gov. I have a blog-type set up for a Message of the Day and everything is working great.

    But... I want to be able to apply a 'New Post' icon on the latest message titles that runs for 24 hours then turns to a standard icon.

    I'm currently using a Font Awesome icon next to the post title in the list, and I'm pretty much asking if there's a way to make one icon show for 24 hours and then a different icon show forever after?

    any help would be much appreciated.

    thanks

    Ben

  • Sven Geusens 161 posts 869 karma points c-trib
    May 30, 2017 @ 14:38
    Sven Geusens
    1

    Check the Nodes createDate + 1 versus current datetime And change the iconName accordingly

    @{
        // node is the node you want to check
    
        var isRecent = node.CreateDate.AddDays(1) > DateTime.Now;
        var iconName = isRecent ? "fa-snowflake-o" : "fa-asterisk";
    }
    //Somewhere in your razor
    <i class="fa @iconName" aria-hidden="true"></i>
    
  • Ben Evans 5 posts 85 karma points
    May 31, 2017 @ 08:58
    Ben Evans
    0

    Hi Sven, that's exactly what I'm after! so here's my current Partial 'displaying list' block....

    @if (selection.Any())
    {
        <div class="motd-block">
    
            <div class="row">
                @foreach (var item in selection.Take(12))
                {
                    <div class="col-xs-12 col-md-12">
                        <div class="promo-item">
                            @DisplayImage(item)
                            <strong><i class="fa fa-comment-o"></i><a href="@item.Url">
                                    @item.GetPropertyValue("title", item.Name)
                                </a>
                            </strong>
                        </div>
                    </div>
    
                }
            </div>
        </div>
    
    }
    

    Can I put all of that code in this Partial or just the

    <i class="fa @iconName" aria-hidden="true"></i>
    

    and run the rest from another place?

    Thanks again for your help!

  • Sven Geusens 161 posts 869 karma points c-trib
    May 31, 2017 @ 09:03
    Sven Geusens
    100

    This should work

    @if (selection.Any())
    {
        <div class="motd-block">
    
            <div class="row">
                @foreach (var item in selection.Take(12))
                {
                    // check every item if its a recent one and get the correct iconName to display
                    var isRecent = item.CreateDate.AddDays(1) > DateTime.Now;
                    var iconName = isRecent ? "fa-snowflake-o" : "fa-comment-o";
    
                    <div class="col-xs-12 col-md-12">
                        <div class="promo-item">
                            @DisplayImage(item)
                            <strong><i class="fa @iconName"></i><a href="@item.Url"> // Insert the correct iconName
                                    @item.GetPropertyValue("title", item.Name)
                                </a>
                            </strong>
                        </div>
                    </div>
    
                }
            </div>
        </div>
    }
    

    Welcome to the Umbraco community btw :) you are now one of us!

    Don't forget to mark the correct answer so future visitors can easily find it.

  • Ben Evans 5 posts 85 karma points
    May 31, 2017 @ 09:50
    Ben Evans
    0

    Works perfect, you're a star!

    thanks for your help :)

  • 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