New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Hi,

    Is there a way to change the (alias variable) for symlinks resources?

    I mean, i created 1 resource(lest call it master), fillrd in the content with text, and then created like 5 copys(symlinks) everywhere in my site(please, forget about SEO implications for having duplicates, i resolved that qith 1 index,follo XD ).

    But now i want to change the alias for my "master" resource, but i realized i have to change the alias for those symlinks too?

    i believed that changing the alias in the master would replicate to all the symlinks, but sadly, they dont change sad

    do i have to change it manually?

    Thanks

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      I'm afraid so. MODX doesn't maintain an internal link from a master to its Symlinks.

      You could do it with a utility snippet like this (untested):

      Put this tag in a resource:

      [[FixSymlinks]]



      Then create a snippet called FixSymlinks with this code:

      /* FixSymlinks snippet */
      $masterId = 12; // replace 12 with the ID of the master
      $master = $modx->getObject('modResource', $masterId);
      $alias = $master->get('alias');
      $sls = $modx->getCollection('modResource', array('content' => $masterId));
      
      if (empty($sls)) {
         return "<p>No Symlinks found</p>";
      }
      
      $count = 0;
      foreach($sls as $symlink) {
         $symlink->set('alias', $alias);
         if ($symlink->save()) {
            $count++;
         }
      }
      
      return "<p>" . $count . " Symlinks fixed</p>";
      


      Then view the resource with the tag.

      You can use it on multiple masters by changing the $masterId.
        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
      • Quote from: BobRay at Sep 19, 2018, 05:24 PM
        I'm afraid so. MODX doesn't maintain an internal link from a master to its Symlinks.

        Thanks Bob, that would be a nice modx feature(at least for me, right now) ill have to change it manually now sad

        i will use the utility provided, for another purposes smiley

        Thanks