On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Just a quick tip while it's in my head (from updating my band's sadly neglected site).

    I wanted to put the current year in the footer of my site, without bothering with a snippet. (If there are any magic settings containing the current time, I could not recall. Maybe there are.) But here's a simple way to do it in any case:

    [[!+nowdate:default=`now`:strtotime:date=`%Y`]]


    The "nowdate" placeholder doesn't really exist, but giving it a default value of "now" gets you a value to pass along. Pass that to the strtotime filter, you get the current unix timestamp. Pass that to the date filter, you get any representation of the current date you want.
    [ed. note: netProphET last edited this post 5 years ago.]
      Mike Schell
      Lead Developer, MODX Cloud
      Email: mike@modx.com
      GitHub: https://github.com/netProphET/
      Twitter: @mkschell
    • If you want this to change with the actual date, you need to call it uncached.
        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
      • Right you are, Susan!
          Mike Schell
          Lead Developer, MODX Cloud
          Email: mike@modx.com
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
        • Brilliant. smiley

          I imagine instead of `now` you could probably use `tomorrow` `yesterday` `next week` `next thursday` etc.
            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
          • The "now" is simply passed on to the PHP strtotime function internally. So any legal parameter to strtotime could be used.
            [[+nowdate:default=`2 years ago`:strtotime:date=`%Y`]]



            Examples from here http://php.net/manual/en/function.strtotime.php

            <?php
            echo strtotime("now"), "\n";
            echo strtotime("10 September 2000"), "\n";
            echo strtotime("+1 day"), "\n";
            echo strtotime("+1 week"), "\n";
            echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
            echo strtotime("next Thursday"), "\n";
            echo strtotime("last Monday"), "\n";
            ?>
            
              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
            • Great found!
              Thanks for sharing
              Would be another good example for chaining multiple output-filters at rtfm:
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
              • Just be aware that it will be a lot more processing-intensive, and thus slower, than a simple snippet, like the CopyYears snippet, which will display the current year or a range of years, like '2000-2014'
                $now = date("Y");
                $startYear = $modx->getOption('startYear', $scriptProperties, $now);
                $spacer = $modx->getOption('spacer', $scriptProperties, '-');
                $years = ($now > $startYear) ? $startYear.$spacer.$now : $now;
                return $years;
                  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
                • Quote from: sottwell at Oct 31, 2014, 06:25 AM
                  Just be aware that it will be a lot more processing-intensive, and thus slower, than a simple snippet, like the CopyYears snippet, which will display the current year or a range of years, like '2000-2014'
                  $now = date("Y");
                  $startYear = $modx->getOption('startYear', $scriptProperties, $now);
                  $spacer = $modx->getOption('spacer', $scriptProperties, '-');
                  $years = ($now > $startYear) ? $startYear.$spacer.$now : $now;
                  return $years;

                  have a snippet 'loop'

                  $loops = $modx->getOption('loops',$scriptProperties,10);
                  $tpl = $modx->getOption('tpl',$scriptProperties,'');
                  
                  for ($i=0; $i < $loops; $i++){
                      $p['idx'] = $i;
                      $output[] = $modx->getChunk($tpl,$p);
                  }
                  
                  $output = implode('<br />',$output);
                  
                  return $output;


                  another snippet 'nowdate':
                  return strftime('%Y-%m-%d %H:%M:%S');


                  I call it:

                  [[!loop? &loops=`10000` &tpl=`nowdate`]]


                  having in the nowdate-chunk:
                  [[!+nowdate:default=`now`:strtotime:date=`%Y-%m-%d %H:%M:%S`]]


                  first output: 2014-10-31 07:09:09
                  last output: 2014-10-31 07:09:20

                  having in the nowdate-chunk:
                  [[!nowdate]]


                  first output: 2014-10-31 07:21:34
                  last output: 2014-10-31 07:21:50


                  So, I don't know why,
                  but with the output-filter-version, I have allways about 10secs between the first and last output.
                  With the snippet-version, I have allways about 15secs for 10000 loops.


                  When I replace getChunk in the snippet with strftime directly:

                  $loops = $modx->getOption('loops',$scriptProperties,10);
                  $tpl = $modx->getOption('tpl',$scriptProperties,'');
                  
                  for ($i=0; $i < $loops; $i++){
                      $p['idx'] = $i;
                      $output[] = strftime('%Y-%m-%d %H:%M:%S');
                  }
                  
                  $output = implode('<br />',$output);
                  
                  return $output;


                  there is no difference between the first and last output, so much less than one second without the getChunk - parsing - process.





                  [ed. note: Bruno17 last edited this post 5 years ago.]
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                  • Ok. Sounds good. Not enough difference either way to make a difference.
                      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
                    • Quote from: netProphET at Oct 30, 2014, 11:01 PM
                      Just a quick tip while it's in my head (from updating my band's sadly neglected site).

                      I wanted to put the current year in the footer of my site, without bothering with a snippet. (If there are any magic settings containing the current time, I could not recall. Maybe there are.) But here's a simple way to do it in any case:

                      [[!+nowdate:default=`now`:strtotime:date=`%Y`]]


                      The "nowdate" placeholder doesn't really exist, but giving it a default value of "now" gets you a value to pass along. Pass that to the strtotime filter, you get the current unix timestamp. Pass that to the date filter, you get any representation of the current date you want.

                      This is One Percent Pure Genius - of the rarest kind!
                      And Ninety-Nine Percent Perspicuity!
                        TinymceWrapper: Complete back/frontend content solution.
                        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.