Snippet · Mecha CMS

Code snippet collection for developers.

Static Time Field

Author: Taufik Nurrohman · 494 Views


Automatically generate static time data on the first page visit, so that updating the page files will not change its publication time.

Hook::set('shield.enter', function() use($site) {
    if ($page = Lot::get('page')) {
        $time = Path::F($page->path) . DS . '';
        if ($site->is !== '404' && !File::exist($time)) {

Note: The default shield uses $page->update to show the current date which will output the file modification time as the page date. To show the current page date created by this snippet, you can use $page->time or $page->date->{$format}:

<p><?php echo $page->date->en_us; ?></p>

Related: $date->extract()


No comments yet.