I’m trying to use multiple dates fields like this:
date:
label: Date
type: date
update:
label: Update
type: date
<time datetime="<?= $item->date()->toDate('%d.%m.%Y') ?>"><?= $item->date()->toDate('%d.%m.%Y') ?></time>
<span>Updated: </span><time datetime="<?= $item->update()->toDate('%d.%m.%Y') ?>"><?= $item->update()->toDate('%d.%m.%Y') ?></time>
But update is not shown. Is it possible to use multiple dates ?
Thank you.
Yes, rename it to something else if you don’t want to update the page instead.
Your friendly
^^ right it works better like this…
Your friendly
Can I take this oportunity to ask how I could include the update date in loop sortBy date desc?
The idea is to use the update date instead of date if it used.
Or maybe it is better to open a new topic?
I’d create a page model that returns either one or the other, then use that for sorting.
<?php
class WhateverPage extends Page {
public function sortDate()
{
return $this->update()->isNotEmpty() ? $this->update()->toDate('%d.%m.%Y') : $this->date()->toDate('%d.%m.%Y');
}
}
In template:
$sortedArticles = $page->children()->sortBy('sortDate');
thank you and sorry, it does not work. Order of articles is mixed and sort by asc or desc have no effect. Maybe all ‘publisedupdate’ fields should not be left empty ?
Ah, maybe it doesn’t work with the formatting, either remove that or change it to %Y%m%d
.
Unfortunatly not, my model uses date a first time for others needs, maybe that breacks something ?
<?php
class NewPage extends Page
{
public function peryear()
{
return $this->date()->toDate('%Y');
}
public function sortDate()
{
return $this->publisedupdate()->isNotEmpty() ? $this->publisedupdate()->toDate('%Y%m%d') : $this->date()->toDate('%Y%m%d');
}
}