We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31283
    • 22 Posts
    Hello, new to ModX here and ran into an issue I’m not sure how to solve. I’d appreciate any help.

    What I’d like to do is the following:


    • Home page contains snippet which evaluates the current month and year.
    • Automatically fowards / displays a page pertaining to that date, based on the page’s alias.

    So for example, something along the lines of:

    <?php
    $currentMonth = date("m.Y");
    $modx->sendForward($currentMonth);
    ?>


    Where the Home page would then automatically display my page with a URL Alias of (currently) "05.2010".

    I realize that ’sendForward’ should be using an id instead of an alias, but ideally I’d like to be able to retrieve the alias of other documents without knowing that document’s id.

    Is this possible?
      • 21191
      • 236 Posts
      This smells like a job for phx and it’s date format function. That’s where I’d start.
        ~Shawn Himmelberger
        Check out my MODx Development and MODx Design Company - Himmelberger Design
        • 31283
        • 22 Posts
        Thanks for the feedback. I think I found a quick and dirty solution here:

        <?php
            $currentMonth = date("m.Y");
            $newDoc = $modx->getDocumentObject('alias',$currentMonth);
            $id = $newDoc['id'];
            $modx->sendForward($id);
        ?>
          • 22303 MODX Staff
          • 10,725 Posts
          You should never call getDocumentObject(); this is an internal method only.

          You can look up the id’s by alias in $modx->documentListing much more efficiently:
          <?php
          $currentMonth = date("m.Y");
          if (array_key_exists($currentMonth, $modx->documentListing)) {
              $modx->sendForward($modx->documentListing[$currentMonth]);
          }
          ?>