Copied to clipboard

Flag this post as spam?

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


  • Johan 95 posts 264 karma points
    Dec 07, 2015 @ 15:56
    Johan
    0

    Edit "created" date and time

    I'm wondering if it possible to make it so that the user is able to pick a "Created" time of a site and if nothing is entered, the current time is used.

    Is this possible?

  • Comment author was deleted

    Dec 07, 2015 @ 16:24

    You could add an additional property to the doc type... and if that is populated use that , if it isn't use the default create date

  • Johan 95 posts 264 karma points
    Dec 07, 2015 @ 16:41
    Johan
    0

    But how can I make it so that it uses the doc type instead of the default in "created"?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 07, 2015 @ 17:31
    Dennis Aaen
    2

    Hi Johan,

    As Tim said you can use a date picker on your document type, with time or not, and then check if the date picker has a value. If not then you can use the create date as fallback value.

    To get the date from a date picker you can use this code.

    @if(CurrentPage.HasValue("date")){
    
        @CurrentPage.date.ToString("dd MMM yyyy")
    }else{
        @CurrentPage.CreateDate
    }
    

    For the date picker with time you should be able to do something like this.

    @if(CurrentPage.HasValue("date")){
    
        @CurrentPage.date.ToString("dd MMM yyyy hh:mm tt")
    }else{
        @CurrentPage.CreateDate
    }
    

    Remember to change the alias of date so it match your alias for your date picker.

    Hope this helps,

    /Dennis

  • Comment author was deleted

    Dec 07, 2015 @ 16:42

    On your frontend? Well in your views you can just output what you want...

  • Johan 95 posts 264 karma points
    Dec 08, 2015 @ 09:51
    Johan
    0

    I tried this in my homepage but it didnt work..

    <div class="col-md-4 news-header">
        <h2>Aktuellt</h2>
        <ul class="startpagelist">
            @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("createDate descending").Take(5))
            {
                <li>
                    <article>
                        <a href="@page.Url">
                            <div class="article-content">
                                <h3>
                                    @page.Name
                                </h3>
                                <span class="information">
    
                                    @if (CurrentPage.HasValue("publiceringstid"))
                                    {
    
                                        @CurrentPage.date.ToString("dd MMM yyyy hh:mm tt")
                                    }
                                    else
                                    {
                                        @CurrentPage.CreateDate
                                    }
                                </span>
                                <p>
                                    @StripHtmlTags(page.innehall, 120)
                                </p>
                            </div>
                        </a>
                    </article>
                </li>
            }
        </ul>
    </div>
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 08, 2015 @ 09:55
    Dennis Aaen
    0

    Hi Johan,

    Try change the @CurrentPage in the foreach loop to @page. So your code looks like this.

    When you are in a foreach loop, the the variable is now refers to the current page.

    <div class="col-md-4 news-header">
        <h2>Aktuellt</h2>
        <ul class="startpagelist">
            @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("createDate descending").Take(5))
            {
                <li>
                    <article>
                        <a href="@page.Url">
                            <div class="article-content">
                                <h3>
                                    @page.Name
                                </h3>
                                <span class="information">
    
                                    @if (page.HasValue("publiceringstid"))
                                    {
    
                                        @page.date.ToString("dd MMM yyyy hh:mm tt")
                                    }
                                    else
                                    {
                                        @page.CreateDate
                                    }
                                </span>
                                <p>
                                    @StripHtmlTags(page.innehall, 120)
                                </p>
                            </div>
                        </a>
                    </article>
                </li>
            }
        </ul>
    </div>
    

    Hope this helps,

    /Dennis

  • Marko Jovanov 10 posts 115 karma points
    Dec 08, 2015 @ 09:58
    Marko Jovanov
    0

    Your OrderBy doesn't seem correct.

    Try using it as lambda call: OrderByDescending(x => x.CreateDate).Take(5)

  • Johan 95 posts 264 karma points
    Dec 08, 2015 @ 10:10
    Johan
    0

    Hi Dennis,

    I tried that code, but not when a specific date in inputed, the date is not showing. Only pages that has the default current time is displaying its current date. The custom date is not displaying. Do you know what could be the problem?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 08, 2015 @ 10:24
    Dennis Aaen
    0

    Hi Johan,

    First, try to change:

    @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("createDate descending").Take(5))
    

    to

    @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("createDate desc").Take(5))
    

    Also make sure that the page that you are looping over has a date picked in the page.

    Hope this helps,

    /Dennis

  • Johan 95 posts 264 karma points
    Dec 08, 2015 @ 10:35
    Johan
    0

    Hi Dennis,

    For some reason this @page.date.ToString("dd MMM yyyy") doesnt seem to work.

    Only the ones that doesn't have a picked date shows the current date.

    The page that has a picked date by the user doesnt show the date.

               @if (page.HasValue("publiceringstid"))
                      {
    
                                @page.date.ToString("dd MMM yyyy")
                       }
                     else
                        {
                               @page.CreateDate
                        }
    

    The @page.date.ToString("dd MMM yyyy") doesn't seem to work. Are you sure it's correct code?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 08, 2015 @ 10:43
    Dennis Aaen
    0

    Hi Johan,

    Oh now I see why :- )

    This @page.date.ToString("dd MMM yyyy") needs to be:

     @page.publiceringstid.ToString("dd MMM yyyy")
    

    Hope this helps,

    /Dennis

  • Johan 95 posts 264 karma points
    Dec 08, 2015 @ 12:16
    Johan
    0

    Thank you :)

    How can I order by that?

     @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("createDate desc").Take(5))
    

    this code only orders by the default createDate, how can I make it so it orders by both the date picker and the createDate?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 08, 2015 @ 12:20
    Dennis Aaen
    0

    Try to do something like this

     @foreach (var page in Umbraco.Content(CurrentPage.pagelistRoot).Children.OrderBy("publiceringstid,createDate desc").Take(5))
    

    What this will do is first sort by the publiceringstid, and then by createDate

    Will this work for you?

    /Dennis

  • Johan 95 posts 264 karma points
    Dec 08, 2015 @ 12:46
    Johan
    0

    Well it works by that it first sort by the publiserigstid and then createDate, but I need to sort by for both at the same time..

    Is there any way to do this?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Dec 08, 2015 @ 13:19
    Dennis Aaen
    100

    Hi Johan,

    I don´t think it´s possible to sort on two properties at the same time. You need to sort at one property and then another.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft