On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I just upgraded form 2.0.x to 2.2. I have a lof of resources without aliases, and old links that used to get built replacing a missing alias with the id, now no longer work. I can see in the content table that the uris for many resources use this old format (which was great and should still work, dammit smiley

    /content/123/23/overview.html

    I have hundreds of such uris that now don't work, and dozens of containers without aliases. Is there a way to get all the aliases created automatically at once. And can ew go back to the old url scheme, too?! [ed. note: drwagner13 last edited this post 7 years, 3 months ago.]
      Revo 2.0.8-pl
    • Here's a utility snippet that should create standard aliases for them, though any hard-coded links, links creates in code without using $modx->makeUrl(), or off-site links still won't work:

      [[!FixAliases]]


      Just create the snippet, put that tag on a page, a preview the page (just once). Then clear the cache and delete the snippet and page.

      <?php
      /* FixAliases snippet */
       
      $resources = $modx->getCollection('modResource');
       
      $count = 0;
      
      foreach ($resources as $resource ) {
          $alias = $resource->get('alias');
          if (empty($alias) )  {
               $count++
               $pageTitle = $resource->get('pagetitle');
               $newAlias = $resource->cleanAlias($pageTitle);
               $resource->set('alias', $newAlias);
          }
       
       $resource->save();
      }
      
      return 'Created new aliases for ' . $count . 'resources';
      


      That will give you aliases that are lowercase versions of the pagetitle with any spaces converted to hyphens.

      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 7 years, 3 months ago.]
        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
      • This appears to have worked perfectly. You are a lifesaver.
          Revo 2.0.8-pl
        • I'm glad it worked. Thanks for reporting back. smiley

          Please reply and edit the subject to add [Solved].

          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
          • There was a request for fixing empty menu titles. This works just like the snippet above but replaces empty menu titles with the pagetitle:

            <?php
            /* FixAliases snippet */
              
            $resources = $modx->getCollection('modResource');
              
            $count = 0;
             
            foreach ($resources as $resource ) {
                $menutitle = $resource->get('menutitle');
                if (empty($menutitle) )  {
                     $count++
                     $pageTitle = $resource->get('pagetitle');
                     $newMenuTitle = $pageTitle;
                     $resource->set('menutitle', $newMenuTitle);
                }
              
             $resource->save();
            }
             
            return 'Created new menutitles for ' . $count . 'resources';
              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