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

    I don’t if such plugins/snippets excist, but I would like a snippet that includes the date of the latest update of a document. Also I would like a snippet that can be used on the frontpage that shows the newest documents and the latest updated documents.

    Is this possible?
      • 34162
      • 1 Posts
      It does not only exist, but it is also part of the "default Template". Its name is "ListIndexer" [[ListIndexer?LIn_root=0]] and lists the most recently changed docs.
      You could do that with Ditto too, but Ditto has a lot of more options, so it’s harder to configure for a beginner.
        • 4041
        • 788 Posts
        List Indexer works fine to show multiple document edits, but this snippet here will show either the created on or edited on date for a specific document -

        /*
          last_updated
          last edit:  2/07/06  9:30 pm est
          Usage: [!last_updated?dateFormat=%B %e, %Y!] Returns date formatted: July 13, 2005
          See strftime() documentation for additional formatting options
        */
        // Default Date/Time format to use if not sent in snippet call
        $format = isset($dateFormat) ? $dateFormat : "%B %e, %Y";
        
        // added a message to show
        $update_pre ="<span class='smtxtblue'>This document was ";
        $update_suf ="</span>";
        
        //$page_id =$modx->documentObject['id'];
        
        $doc_created =  $modx->documentObject['createdon'];
        $doc_edited = $modx->documentObject['editedon'];
        
         if($doc_edited ==""){
            $update_date = strftime($format,$doc_created);
            $update_text = "created on ";
           }else{
            $update_date = strftime($format,$doc_edited);
            $update_text = "modified on ";
           }
        
        $update = "$update_pre $update_text $update_date $update_suf";
        return $update; 
        


        just add this into either the document or the template and it will print whatever text you want to show, as it is now the outout is:

        This document was modified on July 26, 2006

        to change the output format, modify the following areas:
        $update_pre
        $update_suf
        $update_text - "modified on "; / "created on";
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 34162
          • 1 Posts
          Yes, that will work. But I find it a bit more complicated than necessary:
          You do not have to run a sql-query directly against the site_content table.
          The fields in question are members of the Document-array:
          $modx->documentObject[’createdon’]
          $modx->documentObject[’editedon’]
          as documented in http://modxcms.com/the-document-object.html.

          These calls will deliver the dates in question directly. The benefit is, that it will run much faster, will obey user-access rights and will most likely run with future versions of MODx, since the structure of the site_content table is subject to changes.

          EDIT: See you’ve changed your snippet already, Breezer. That was quick! Just mention it for future readers not being confused when reading this thread.. ;-)
            • 7923
            • 4,213 Posts
            Yes, for the timestamp in one specific document, look at http://modxcms.com/AuthorTimestamp-693.html


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 4041
              • 788 Posts
              yes sir, that works fine and dandy...

              I fixed the snippet at the top as well as my personal copy, you’ll have to cut me a bit of slack as I am steadily reworking all my older snippets to work with modx grin
                xforum
                http://frsbuilders.net (under construction) forum for evolution