Copied to clipboard

Flag this post as spam?

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


  • ChrysDW 5 posts 25 karma points
    Mar 29, 2014 @ 21:23
    ChrysDW
    0

    Check date value of child

    I am trying to check the listedPublishDate value of children, if the listedPublishDate equals today then for every page that matches the date, display contents of that child; if a page does not exist with the matching listedPublishDate date then I would like to have hardcoded text.  Something like this:

    var displayDate = DateTime.Today.ToString("MMM d, yyyy");

    @if (CurrentPage.Children.Where("listedPublishDate == displayDate"))
    {    

    @foreach (var page in pages)
    { 
    @page.Name
    @page.Content
    }
    else 

    {
    Hello World
    }
    }

     

     

    Thanks in advance,
    Chrys 

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

    Hi Chrys,

    Welcome to Our!

    You are very close already but a few tweaks below for you:

    @{
        var pages = CurrentPage.Children.Where("listedPublishDate == @0", DateTime.Today.Date);
    
        if (pages.Any())
        {
            foreach (var page in pages)
            {
                <p>
                    @page.Name
                    @page.Content
                </p>
            }
        }
        else
        {
            <p>
                Hello World
            </p>
        }
    }
    

    I've assumed in this snippet that listedPublishDate is a Date Picker property editor.

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft