We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39273
    • 61 Posts
    Howdy all:

    In my footer I have the standard Terms of Use, Privacy Policy, etc. Those links in the footer are displayed using Wayfinder. My goal is if I were to modify one of the documents in the footer, Wayfinder somehow could check if the revision date of the resource is less than x days old and if so place "Updated" next to the document name. Am i asking too much of Wayfinder?
    • You need a snippet to determine if the editedon date (a timestamp) is less than today's timestamp minus the number of seconds in x days (86400*$days). Have it return "Updated" if so, or nothing if not. Then you could use that snippet in the rowTpl.
      <li...  [[!updated]]</li>
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 39273
        • 61 Posts
        Duh! I am so stupid. I never thought about placing a snippet in the template. How easy can that be???!! Thank you so much for your help.
          • 39273
          • 61 Posts
          I guess I'm perhaps still stupid. sad

          Here is my snippet:

          <?php
          //
          // Example: [[!Updated? &created_date=`[[*publishedon]]` &revision_date=`[[*editedon]]`]]
          //
          if (time() - strtotime($created_date) < (86400 * 14)) {
              $output = '';
              $output .= $created_date;
              $output = ' <span class="badge">New</span>';
              return $output;
          } elseif (time() - strtotime($revision_date) < (86400 * 14)) {
              $output = '';
              $output .= $revision_date;
              $output = ' <span class="badge">Updated</span>';
              return $output;
          } else {
              return '';
          }


          My template looks like this:

          <a[[+wf.id]][[+wf.classes]] href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>[[!Updated? &created_date=`[[+wf.publishedon]]]` &revision_date=`[[+wf.editedon]]`]]


          You can see from the Example in the code the call I am using to pass the parameters. However, the published date and the edited date are not being passed. What am I missing?
            • 3749
            • 24,544 Posts
            I don't think Wayfinder sets those placeholders.

            BTW, if you want the creation date, you might want 'createdon' rather than 'publishedon'.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 39273
              • 61 Posts
              I chose publishedon rather than createdon just in case I did create a document which I chose not to publish immediately. So is there a work around to pass the publishedon/editedon fields to my snippet?
                • 3749
                • 24,544 Posts
                By default, unpublished docs wouldn't show anyway, so createdon would be more accurate -- unless the publication date is actually what you want (though in that case, I would change the name of the property to avoid confusing myself later wink ).

                What version of Wayfinder are you using? It looks like I was wrong:

                Since version 2.3.0 you can use placeholders for all fields of a Resource, such as [[+introtext]], [[+menutitle]], [[+published]], etc.

                You might try using them without the wf. prefix.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 39273
                  • 61 Posts
                  Newest version of Wayfinder (installed yesterday).

                  First off, I changed $created_date to $published_date for the sake of symantics! smiley

                  Removed the wf. prefix and still the variables are not being passed.
                    • 39273
                    • 61 Posts
                    SOLVED.

                    I resolved the issue by changing my code to:

                    //
                    // Example: [[!Updated? &id=`[[+wf.docid]]`]]
                    //
                    $object = $modx->getObject('modResource',$id);
                    $published_date = $object->get('publishedon');
                    $revision_date = $object->get('editedon');
                    if (time() - strtotime($published_date) < (86400 * 14)) {
                        $output = '';
                        $output .= $created_date;
                        $output = ' <span class="badge">New</span>';
                        return $output;
                    } elseif (time() - strtotime($revision_date) < (86400 * 14)) {
                        $output = '';
                        $output .= $revision_date;
                        $output = ' <span class="badge">Updated</span>';
                        return $output;
                    } else {
                        return '';
                    }
                      • 39273
                      • 61 Posts
                      SOLVED.

                      I resolved the issue by changing my code to:

                      //
                      // Example: [[!Updated? &id=`[[+wf.docid]]`]]
                      //
                      $object = $modx->getObject('modResource',$id);
                      $published_date = $object->get('publishedon');
                      $revision_date = $object->get('editedon');
                      if (time() - strtotime($published_date) < (86400 * 14)) {
                          $output = '';
                          $output .= $created_date;
                          $output = ' <span class="badge">New</span>';
                          return $output;
                      } elseif (time() - strtotime($revision_date) < (86400 * 14)) {
                          $output = '';
                          $output .= $revision_date;
                          $output = ' <span class="badge">Updated</span>';
                          return $output;
                      } else {
                          return '';
                      }