I'm not really wrapping my head around Ext JS, but I'm working through the
assets/components/articles/js/container/container.articles.grid.js file and I spotted this around line 172:
,_makeTemplates: function() {
this.tplPublished = new Ext.XTemplate('<tpl for=".">'
+'<div class="articles-grid-date">{publishedon_date}<span class="articles-grid-time">{publishedon_time}</span></div>'
+'</tpl>'
I noticed that some of the placeholders here are NOT standard MODX field names (e.g "publishedon_date" instead of the standard "publishedon"), so clearly, some manipulation is happening behind the scenes somewhere. And that location is inside the
core/components/articles/processors/article/getlist.class.php file.
So looking inside that file, we can see where these special placeholders are set -- around line 182 of
getlist.class.php:
if (!empty($resourceArray['publishedon'])) {
$resourceArray['publishedon_date'] = strftime('%b %d',strtotime($resourceArray['publishedon']));
$resourceArray['publishedon_time'] = strftime('%H:%I %p',strtotime($resourceArray['publishedon']));
$resourceArray['publishedon'] = strftime('%b %d, %Y %H:%I %p',strtotime($resourceArray['publishedon']));
}
So you can display the year in your article listing by hacking these two files.
First, calculate the year in PHP and add that to the $resourceArray like this:
if (!empty($resourceArray['publishedon'])) {
$resourceArray['publishedon_date'] = strftime('%b %d',strtotime($resourceArray['publishedon']));
$resourceArray['publishedon_time'] = strftime('%H:%I %p',strtotime($resourceArray['publishedon']));
$resourceArray['publishedon'] = strftime('%b %d, %Y %H:%I %p',strtotime($resourceArray['publishedon']));
$resourceArray['publishedon_year'] = strftime('%Y',strtotime($resourceArray['publishedon']));
}
See that? I just added one more placeholder for 'publishedon_year' and I used the %Y date format string.
Next, I update the template inside the
container.articles.grid.js file to use my new placeholder:
<div class="articles-grid-date">{publishedon_date}, {publishedon_year}<span class="articles-grid-time">{publishedon_time}</span></div>
There is one more place where you have to make an edit. Still in the
container.articles.grid.js file around line 20 there is a key for "fields". Your new "publishedon_year" placeholder will be ignored if you don't add it to this array:
,fields: ['id','pagetitle',
'publishedon','publishedon_date','publishedon_time','publishedon_year',
'uri','uri_override','preview_url',
'createdby','createdby_username','tags','categories',
'actions','action_edit','content','comments']
Then I clear my MODX cache and my browser cache and now I can see the year in my Articles listing (see attached image).
WARNING: the above steps represent a complete hack of the Articles plugin. Updating the plugin would destroy all of these customizations. I'm just documenting this so other people can see how Ext JS works in a real live example.
[ed. note: Everettg_99 last edited this post 11 years, 2 months ago.]