We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36491
    • 36 Posts
    Hi!

    In the manager, the Articles container shows a list of documents. The list shows the publication date, but only in the form "month day, time(am/pm)".

    For my client I need the year also to be displayed. And 24h-time format would be nice. Where can I set the format string?

    modx 2.2.6, Articles 1.6.3

    Thanks!
    Jörg
    • This would be huge: is there a way to customize the display of the data in the MODX manager? Another thread pointed to MIGX: http://rtfm.modx.com/display/ADDON/MIGXdb.Manage+Child-Resources+in+a+grid-TV+with+help+of+MIGXdb

      But it would make sense if you could do this natively inside of Articles.
        • 36491
        • 36 Posts
        The MIGX-solution would be really be like using a sledgehammer to break a nut.

        Quote from: Everettg_99 at Feb 06, 2013, 10:09 PM
        But it would make sense if you could do this natively inside of Articles.

        Yesy, it should be a customization option.
        • Yeah, that would be awesome... I posted another thread that essentially boils down to this same thing: http://forums.modx.com/thread/82268/how-can-i-customize-the-display-of-the-list-of-articles-inside-the-modx-manager#dis-post-454091
          • 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.]
            • FYI, I added this as a refactor request: http://tracker.modx.com/issues/9508
                • 36491
                • 36 Posts
                Fixed in Articles-1.6.4. New option:

                articles.mgr_date_format


                Thanks, Jason!

                Jörg