Closed omniperspective closed 5 years ago
You'll have to create a plugin to get this done - but don't despair, it's pretty simple. Just take the following few lines (taken from https://github.com/PhrozenByte/pico-robots):
class PicoModTimePlugin extends AbstractPicoPlugin
{
public function onSinglePageLoaded(array &$pageData)
{
if ($pageData['id']) {
$fileName = $this->getConfig('content_dir') . $pageData['id'] . $this->getConfig('content_ext');
if (file_exists($fileName) && !isset($pageData['modificationTime'])) {
$pageData['modificationTime'] = filemtime($fileName);
}
}
}
}
You can then access the modification time of a page's content file using {{ page.modificationTime|date("m/d/Y") }}
. Please note that this might not be what you actually want, the modification time might geht updated by your operating system even if you didn't change anything. Thus I'd recommend using a meta header instead.
Unfortunatly there's no way to tell when a file has been created on Linux (to be precise, whether it is possible or not depends on the filesystem you use, and if it is possible, the code necessary to access this information might vary). I again recommend using a meta header instead (e.g. Pico's default Date
meta header).
Thanks Phrozenbyte for the extended reply, as always great support, and a good start for me.
This will be my first project to build a PicoCMS plugin.
kind regards Henk.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:
Question:
Is picocms able to give me the creation and modification time of a file, is there a { page.??? } variable that holds that data? Can't find it in the twig documentation other than changing the format. Hense is there a possibility to use a unix library call to get info into the picocms framework? or do I have to write a plugin to get this done.
regards Henk.