Shorewalker
  • Home
  • Site-building
    • Content management systems
    • MODX
    • User experience, user persuasion
    • Website project management
  • Public policy
    • The Finkelstein Review's fatal flaws
    • The broadband cargo cult, dissected
    • High-speed rail: an expensive hobby
    • Big infrastructure, big uncertainty
  • Culture & tech
    • Washed ashore: a list of links
    • Bruno Latour and the end of postmodernism
    • Photographing Wilsons Promontory
    • How hacking really works - and how we're making it easier
    • In defence of George Lazenby, the Aussie James Bond
    • ABC Spirit Of Things issues
  • Archive
    • The CEO Magazine columns
    • The Age/SMH columns
  • About
  • Search
  •  
  • Site-building /
  • MODX /
  • MODX time functions: harder than they look

MODX time functions: harder than they look

By David Walker (Google profile)

Occasionally you come across something in MODX that is harder than it has any right to be. Take today's date and time. You'd think there'd be a MODX thingumujjig to spit it out. Nope. You'll have to build a snippet. Considering everything MODX does for you, the inability to just summon up a date or time is just odd.

Best solution comes from MODX architect Jason Coward (Opengeek): Create a generalised time snippet (I named mine functionTime) and call it with an output filter applied. Previously I was using a snippet that created the year; this allows you to use the output filter to create any date/time combination.

Snippet:

    <?php
    return time();
    ?>

Snippet call in page:

[ [!functionTime:date=`%Y`] ]

And once you have this call, you can display and type of date and time. While finding out the time is unexpectedly hard in MODX, date formatting is easy.

References

  • MODX forums: Generate years for copyright notice ...
  • MODX RTFM: Input and Output Filters (Output Modfiers)
  • MODX RTFM: Date formats

Filed on 8 July 2012 and last updated on 27 January 2013

Copyright 1995-2025 David Walker

Page info

...
...
×

Next Previous Slideshow Download