Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    Jul 28, 2014 @ 22:22
    John Churchley
    1

    Getting the "Publish at" property in a view

    I'm trying to obtain the "Publish at" date in a view in Umbraco 7 

    I've attempted to do as described here http://our.umbraco.org/forum/developers/api-questions/39280-Getting-values-for-Publish-At-Remove-At-fields-using-C

    However it now obsolete and advices to used Umbraco.Core.Models.Content any ideas?

    Another suggestion is to use the Umbraco.Core.Models.IContent interface however I'm unsure how to create an instance for it to work. 

    Is there another easier method through the @Umbraco helper?

     

     

     

     

     

  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 28, 2014 @ 22:52
    Allan Molsen Larsen
    0

    Hi John

    @Model.Content.UpdateDate should do the trick.

    http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content

    -Allan

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 28, 2014 @ 22:56
    John Churchley
    0

    Hi Allan unfortunately i'm not after the UpdateDate as this can change if someone goes back and made alterations to the page (i,e, improve spelling). 

    My attempt at creating an instance of the IContent 

    var updateDate = new Umbraco.Core.Models.Content("Page", Model.Content.Id,?????);

  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 28, 2014 @ 23:25
    Allan Molsen Larsen
    0

    Hi John, I'm not totally sure about this. I'm not on the PC now. But changes to a page that are not published are not in the XML cache. So the updateDate you get on Model is from the last publish.

    I'll have to try it tomorrow, but I think this is what I use in one of my own solutions.

    -Allan

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 29, 2014 @ 00:02
    John Churchley
    0

    Hi Allan that would be great thanks!

     

  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 29, 2014 @ 08:57
    Allan Molsen Larsen
    0

    Hi again,

    Just checked up and made a test.

    When you work with Model.Content.UpdateDate you get the published content from the cache. The value of UpdateDate on the published content is the publish timestamp.

    If you edit content without publishing the published content in the cache will not be changed and the updateDate will not be updated. 

    /Allan

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 29, 2014 @ 22:39
    John Churchley
    0

    HI Allan, I'm after a solution which is robust as happy clickers like myself will aways kick publish and think after but thanks for the suggestion. I'm sure there must be a way as the fields get populated somehow!

  • Allan Molsen Larsen 22 posts 192 karma points
    Jul 29, 2014 @ 22:47
    Allan Molsen Larsen
    0

    Hi John

    I'm propably misunderstanding what you really want. Whenever you click publish on content in Umbraco your publishdate (updateDate) will be updated as a new version of the content is created.

    Is this not what you want? Is it the initial publish date you want?

    /Allan

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 30, 2014 @ 00:51
    John Churchley
    1

    Hi Allan, I would like to be able to used the "Publish at" field which will be referenced in some views and used for sorting a group of nodes. I can't use the CreateDate as sometimes the nodes will be created a few day before being release and I need the release date to show on the frontend. I'm not able to use the UpdateDate property because if someone goes back in a republished the node then it will display the wrong new date and there will be no way to revert this back unless a script is run of the DB. I realise I could create a new field called published date using a date picker but this feels very much like duplication and would prefer to use the "Publish at" date. I hope this explains it clearer.

  • John Churchley 272 posts 1258 karma points c-trib
    Aug 05, 2014 @ 22:02
    John Churchley
    0

    Anyone with further ideas on this?

  • Johan 188 posts 380 karma points
    Oct 09, 2014 @ 17:19
    Johan
    0

    Yes, i'm also after this functionality cause i want my editors to be able to backdate posts.

  • Johan 188 posts 380 karma points
    Oct 31, 2014 @ 16:22
    Johan
    0

    I reported this as a bug here http://issues.umbraco.org/issue/U4-5736

  • Jamie 35 posts 87 karma points
    Nov 21, 2014 @ 09:08
    Jamie
    0

    I'm looking into this as well. It seems to me the news template loaded into one of the default themes indicate this can happen. However on testing it does not. I'm just trying to learn razor on 7 after using XSLT only before - so this example seems very misleading.

    // Similar to above: find all pages with document type umbNewsItem under the news overview page
    // Then order them, first by publishDate (a property the editor can explicitly set on the news item)
    // and then by createDate, which is set by Umbraco automatically when a page gets created.
    var newsItems = newsOverview.umbNewsItems.OrderBy("publishDate desc, createDate desc").Take(9);
    
    @foreach (var item in newsItems)
    {
        // If the editor has not explicitly set the publishDate property then show the create date
                            var dateTime = item.PublishDate == default(DateTime) 
                                ? item.CreateDate 
                                : item.PublishDate;                             
    
        @item.CreateDate.ToString("ddd, MMM d, yyyy")
        @item.UpdateDate.ToString("ddd, MMM d, yyyy")
        @item.PublishDate.ToString("ddd, MMM d, yyyy")
        @dateTime.ToString("ddd, MMM d, yyyy")
    }
    

    RESULTS :

    Fri, Nov 21, 2014 (Today) Mon, Jan 1, 0001 (defult / NULL??) Fri, Nov 21, 2014 Fri, Nov 21, 2014

    The snippet above are commented so that IF you created 4 new NEWSITEM nodes today and set the 'Publish At' date for each to be the first of each month for the last 4 months. The past the past date would be shown as it has been set (not null) however in all cases the current CreateDate is shown, and the publishDate ignored.

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Dec 02, 2014 @ 17:52
    Sebastiaan Janssen
    100

    I think there's some confusion here:

    • When you set a date to publish a content item at, this date is NOT published to the cache, so you cannot query it easily
    • Even if you DO manage to query it from the database directly, the field is cleared (set to empty) as soon as the scheduled publish happens
    • You really have only 2 options:
      • Use the UpdateDate (I think this will update as soon as the scheduled publish happens)
      • Create a AfterPublish event handler that sets a date field of your choosing to the current date and time

    In reality if you want to backdate of allow editor to set an arbitrary date when this item was "supposedly" published you will have to give them an extra date field. If they do not fill in that field then you could do a fall-back to CreateDate or UpdateDate (but remember that updates each time someone edits the document). The reason why you really want to add an extra field for them is that a lot of editors will want to make it appear as if an item was published on a certain date and time and they could even cheat with it later, which is completely under their control.

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Dec 02, 2014 @ 17:55
    Sebastiaan Janssen
    0

    And just to make it clear: Umbraco checks every minute "are there any documents that have a Publish At date? if yes: if the Publish At before the current date? if yes: OMG this needs to be published immediately". It then clears the Publish At date so that it doesn't find the same item the next time it does this check (a minute later). If it didn't clear the date it would just keep publishing that item every minute (which would make everybody even more upset.. ;-) )

  • Jamie 35 posts 87 karma points
    Dec 03, 2014 @ 01:58
    Jamie
    0

    That's a good explanation.

    Though perhaps the TXT example package shouldn't use a misleading example of using this field?

  • Johan 188 posts 380 karma points
    Dec 03, 2014 @ 14:38
    Johan
    0

    @Sebastiaan I get that there are technical reasons behind the scenes to why the publishAt property behaves differently to the other properties. This breaks the consistency though and if you (like me) is not to familiar with the back end of Umbraco it's hard to see why. Can't you just put a boolean "isItPublished"-flag to check against instead of removing the property? I know it's not that easy but would a workaround be totally out of the question?

    There are also some problems with the UI (UX-wise). It's a bit counter intuitive to click the "Publish"-button when you have set a Publish At-date. Would be really awesome if it behaved like wordpress in that situation. If a Publish At-date is set, the Publish button change text to "Schedule". And if there is no reason to set a date backwards in time, it should not be possible.

    Maybe if you moved the "Publish At" functionality from the properties tab to be one of the options in the "Save and publish" button everything would make more sense and the consistency would not break cause it wouldn't look like a normal property anymore.

    Off topic: I recently held my first Umbraco 7 class for editors. I was reaaally proud to show off the new Umbraco UI and my clients liked it very much and thought it was a big improvement over their previous CMS. Lots of kudos and #H5YR to the core team! The only thing that didn't really behave as expected was the publish at-property.

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Dec 03, 2014 @ 16:02
    Sebastiaan Janssen
    0

    @Johan We HAVE an IsItPublished flag. You can then alter the published page, save the new content without publishing it and schedule for publishing at a later date. IsItPublished is true, because there is a published version. Anyway, I get that it confuses you and no we can't "just" add a flag for "IsItScheduledForPublishing" that would break all kinds of things as people have gotten used to how it works now and have built their own code with the assumption that this behavior will stay the same (it's not ideal but it works). The workaround I've detailed above (work with an extra field for backdating).

    The UX issue you mention is indeed on our issue tracker somewhere and will get implemented at some point.

    I'm glad that your editors enjoyed Umbraco otherwise!! And sorry about the sometimes quirky behavior, I think this feature dates back about 7 years now so it's kinda hard to change now that people know how it works. We'll get there one day! :-)

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Dec 03, 2014 @ 16:05
    Sebastiaan Janssen
    0

    @Jamie 7.2.0 will have a new default start kit to confuse you in many other ways ;-)

  • Johan 188 posts 380 karma points
    Dec 04, 2014 @ 11:33
    Johan
    0

    @Sebastiaan Yes, that is how i solved it and it works great. Just hard to motivate to clients why there are 2 inputs. I think i found the issue you referred to and will comment there instead. http://issues.umbraco.org/issue/U4-5494

Please Sign in or register to post replies

Write your reply to:

Draft