Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Automatic “Page Created” and “Last Modified” dates in SilverStripe

Simple pieces of code to enable ‘page created’ and ‘last modified’ dates to be added to web page footers.

Many websites will display a “page created” and “page last updated” time stamp somewhere within their footers, particularly websites that are informational. Whilst ‘last modified’ dates can easily be inserted into static websites using some simple PHP, the procedure is a little more complicated with SilverStripe because the code doesn’t rely exclusively on PHP, although PHP date variables are relied-upon.

To add “page created” and “page last updated” time stamps to your page footers, open the file at /themes/YourThemeName/templates/Page.ss in a text editor and add the following code to the footer to output text in the format “Page created: 18 April 2014 12:30pm”

<p>Page created: $Created.Format(d M Y h:i a)</p>

This will display the date and time that the page was initially generated, using the variable $Created.

To display the date and time that the page was last modified, insert the following code into the same file:

<p>Page last modified: $LastEdited.Format(d M Y h:i a)</p>

This utilises the $LastEdited variable in SilverStripe.

Additional documentation about $Created and $LastEdited is available at SilverStripe Docs, although the page has not been updated for the current version of SilverStripe. The arrangement of date/time can be altered to suit one’s own preferences if need-be.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.