We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20508
    • 157 Posts
    Hey Everyone,

    So here’s the situation:

    I have a section on a MODx Website called "Calendar." This page which is a container page housing a page for each month of the year, and should always reflect the current month. What we’re doing now is at the beginning of every month, copying the content for that month and pasting it into the "Calendar" page, so it appears that this page is automatically turning over each month. But in reality - there are two pages with the same content, ie: one for "January" and one for "Calendar."

    This is inefficient - as I’m sure you can see why and becoming more inefficient as the Calendar page is updated a few days a week, every week so updates have to be made to two pages instead of one.

    Is there anyway that anyone knows of to automate this process? For a working example of this, you can go here: http://stirboston.com/index.php?q=calendar

    If you click on "January" in the sidebar, it’s the same content as the "Calendar" page (http://stirboston.com/index.php?q=calendar), but is really two pages.

    Thanks in advance for any recommendations!
    msflux


      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Sure. Just use Ditto, and tell it to take the latest created document, and have your template chunk laid out with everything just the way you want it.
        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
        • 13825
        • 55 Posts
        You could use ditto - but you might have issues with trying to show the correct bread crumb, page title etc...

        I would probably make the parent calendar page a web link - then in the field that you put the document id into use an @EVAL (or equivalent) and some script to call the page with the alias the same as the current month (assuming your pages have aliases of january, february etc...)

        Haven’t tried it - but should work smiley
          • 20508
          • 157 Posts
          In reply to the first reply:

          OK. I’m sure this is super-simple so please bare with me when I ask for further instruction. smiley

          Does the ditto call require anything other than: [+36+]~] ? When I put this into the template where the [*content*] would go, it doesn’t work, so I’m obviously not executing correctly. I’m not using any chunks, except for two which control the sidebar navigation (months) and looks like this:


          <div id="LeftColumn">

          <h1>Classes</h1>

          [!Wayfinder?&startId=`20`&level=3!]




          <h1>Class Archives</h1>
          [!Wayfinder?&startId=`50`&level=3!]

          </div><!--//LeftColumn-->

          Sorry for my lack of knowledge here - haven’t used Ditto extensively.

          Thanks,
          msflux
            • 14050
            • 788 Posts
            I actually wouldn’t use ditto as it would likely add unnecessary overhead for the simple task you are trying to perform. Just do the following:

            Create a snippet called AliasByDate
            <?php
            $today = time();
            $alias = strtolower(date("F-Y",$today));
            return $modx->sendRedirect('?q='.$alias);
            ?>
            


            Then the content of the document called Calendar should only contain the call to the snippet:

            [!AliasByDate!]

            That should do it. Your breadcrumbs should still work because Calendar is still published and the parent of the children. However, if they go to Calendar, they will always be redirected to the page representing the current month. Unfortunately a weblink doesn’t seem to allow evaluation of MODx tags inside its fields. Now I am not 100% certain this is kosher as far as SEO goes, but I will leave that to others.
              Jesse R.
              Consider trying something new and extraordinary.
              Illinois Wine

              Have you considered donating to MODx lately?
              Donate now. Every contribution helps.
              • 20508
              • 157 Posts
              Quote from: Jesse at Jan 09, 2008, 02:51 PM

              I actually wouldn’t use ditto as it would likely add unnecessary overhead for the simple task you are trying to perform. Just do the following:

              Create a snippet called AliasByDate
              <?php
              $today = time();
              $alias = strtolower(date("F-Y",$today));
              return $modx->sendRedirect('?q='.$alias);
              ?>
              


              Then the content of the document called Calendar should only contain the call to the snippet:

              [!AliasByDate!]

              That should do it. Your breadcrumbs should still work because Calendar is still published and the parent of the children. However, if they go to Calendar, they will always be redirected to the page representing the current month. Unfortunately a weblink doesn’t seem to allow evaluation of MODx tags inside its fields. Now I am not 100% certain this is kosher as far as SEO goes, but I will leave that to others.

              Wow, this is awesome and it works perfectly. Thank you so much. smiley
                • 20508
                • 157 Posts
                Quote from: msflux at Jan 09, 2008, 03:09 PM

                Quote from: Jesse at Jan 09, 2008, 02:51 PM

                I actually wouldn’t use ditto as it would likely add unnecessary overhead for the simple task you are trying to perform. Just do the following:

                Create a snippet called AliasByDate
                <?php
                $today = time();
                $alias = strtolower(date("F-Y",$today));
                return $modx->sendRedirect('?q='.$alias);
                ?>
                


                OK, so I just realized that this works in every browser except for Safari, for some reason and I can’t figure out why.

                In other browsers the redirect serves up this URL: http://www.stirboston.com/index.php?q=january-2008

                In Safari it serves up this URL: http://www.stirboston.com/index.php?q=calendar?q=january-2008 (tacks it on to calendar), which results in an "you’ve reached this page in error" message.

                Any idea on how I can fix?

                Thanks,
                msflux


                Then the content of the document called Calendar should only contain the call to the snippet:

                [!AliasByDate!]

                That should do it. Your breadcrumbs should still work because Calendar is still published and the parent of the children. However, if they go to Calendar, they will always be redirected to the page representing the current month. Unfortunately a weblink doesn’t seem to allow evaluation of MODx tags inside its fields. Now I am not 100% certain this is kosher as far as SEO goes, but I will leave that to others.

                Wow, this is awesome and it works perfectly. Thank you so much. smiley
                  • 14050
                  • 788 Posts
                  Maybe this is a problem with the sendRedirect function in the parser class?
                    Jesse R.
                    Consider trying something new and extraordinary.
                    Illinois Wine

                    Have you considered donating to MODx lately?
                    Donate now. Every contribution helps.
                    • 20508
                    • 157 Posts
                    Yeah, I think there’s an issue with this line of code: return $modx->sendRedirect(’?q=’.$alias);

                    However, I don’t know why Safari would be the only browser having issues with it. I’m wondering if there should be a line of code that explicitly says to remove this part of the URL "q=calendar?" and replace with the current alias "q=january-2008"

                    This is the basic code for a redirect, but I don’t know enough about modifying this to make it work for this or if it’s possible:

                    <?php
                    $url = $modx->makeUrl($id);
                    ob_end_clean(); // this will end the output buffer and discard silently what ever was in it
                    header(’Location: ’.$url);
                    ?>
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Might be better to just call the function by itself then return an empty string in the next line. You’re actually returning the return value of that function, probably a success/fail flag.
                        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