Check if a page is currently published

ces55739's Avatar

ces55739

14 Jul, 2014 07:28 PM

Hi,

I am using velocity, and I would like to be able to check if a page is published. Not if it has been published before, but if it is currently published.

Any suggestions?

Thanks!

  1. 1 Posted by Ryan Griffith on 14 Jul, 2014 08:50 PM

    Ryan Griffith's Avatar

    Hi,

    I believe your best bet would be to use the Locator Tool to access additional properties for the Page. Specifically, when reading a Page using the Locator Tool, you will gain access to a lastPublishedOn Date object, which you can compare to the current date.

    Note: you can obtain the current date using the Date Tool's getDate() method, which will return a Date object that you can compare with. Alternatively, you can convert the lastPublishedOn Date object to a Calendar using the Date Tool's toCalendar() method, and compare that to the current Calendar, which can be obtained using the Date Tool's getCalendar() method.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by ces55739 on 14 Jul, 2014 09:01 PM

    ces55739's Avatar

    Doing more research...s there a way to get the true xml node?

    The issue I believe I would have with your solution, is that if a page is unpublished, then it would still be considered "published"

    Thoughts?

  3. 3 Posted by Ryan Griffith on 14 Jul, 2014 09:05 PM

    Ryan Griffith's Avatar

    Hi,

    If the page has not yet been published, the lastPublishedOn property will be null, rather than a Date object. You can check if this property is null using the Property Tool:

    #if ($_PropertyTool.isNull($page.lastPublishedOn) == false)
        ## Process published page logic
    #else
        ## Process unpublished page logic
    #end
    

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by ces55739 on 14 Jul, 2014 09:12 PM

    ces55739's Avatar

    Your code works great!

    If the page gets unpublished, then this code will still say the page is "published". Is there a way to avoid this?

  5. 5 Posted by Ryan Griffith on 15 Jul, 2014 12:30 PM

    Ryan Griffith's Avatar

    Thank you for following up, I am glad to hear the code I provided did the trick.

    If the page gets unpublished, then this code will still say the page is "published". Is there a way to avoid this?

    The system will only keep track of when the asset was last published and by whom, so there would be no way to determine if the asset was unpublished. Part of the issue there is you could technically unpublish the asset from a Destination, but not all, so the asset would still be published.

    Please let me know if you have any questions.

    Thanks!

  6. 6 Posted by ces55739 on 15 Jul, 2014 01:30 PM

    ces55739's Avatar

    Thanks a ton Ryan!

    That is what I was hoping to accomplish, but if it isn't possible I will find a work around.

  7. 7 Posted by Ryan Griffith on 15 Jul, 2014 01:35 PM

    Ryan Griffith's Avatar

    Not a problem at all. My apologies for not having a straight-forward solution for determining if an asset has been unpublished.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  8. Ryan Griffith closed this discussion on 15 Jul, 2014 01:35 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac