On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi all,

    When viewing a resource of type modSymLink, the [[*id]] returns the ID of the original resource (as you would expect).

    Is it possible to retrieve the ID of the modSymLink itself?

    Thanks!
      --
      cal wilson
      oksushi.com
    • Quote from: sushi at Sep 22, 2010, 02:11 PM

      When viewing a resource of type modSymLink, the [[*id]] returns the ID of the original resource (as you would expect).

      Is it possible to retrieve the ID of the modSymLink itself?
      At the current time there is not a way to do this (that I can think of). I would love to hear ideas on how to achieve this before implementing a specific approach. Would you care to enter a ticket for this and maybe we can get some proposals and find the best way to accomplish this in a future release.
      • Issue created: http://bugs.modx.com/browse/MODX-2355

        (I hope I did that right!)
          --
          cal wilson
          oksushi.com
        • The method I am using is a snippet called "getSymlinkId"

          the code is below

          $id= $modx->resource->get(’id’);

          $c = $modx->newQuery(’modResource’);
          $c->select(’content’);
          $c->where(array(’id’=>$id));
          $c->prepare();
          $c->stmt->execute();
          $symlinkId = $c->stmt->fetchColumn();
          $c->stmt->closeCursor();

          if(is_numeric($symlinkId) && !empty($symlinkId))
          {
          return intval($symlinkId);
          }

          This may help, I think it still needs a bit of work, but it does return the symlink Id
          • For those looking for another way to get to the ID of a SymLink itself, I wrote a snippet that does it. This will have been a problem for almost no-one since version 2.0.5-pl when SymLinks were changed to 'overlay' their details on the Target. I found myself in a specific situation though.

            I wanted to set the System Setting 'symlink_merge_fields' to 'No' because it made everything a lot simpler in terms of guaranteeing nothing was overwritten with content drawn from the SymLink. I could list all the exceptions (being every single field in a TV rich template), but then if I ever added another field and forgot to add it to that list, strange behaviour may start to creep in.

            I wanted the SymLink be IDENTICAL to the Target with the only difference being a correct bread crumb based on the location of the SymLink or Target in the structure. Hence I needed the SymLink ID to bait the BreadCrumb extra properly.

            Big thanks to opengeek who supplied the building blocks of this snippet code in a few different places in the forums. The following placed into a snippet will correctly return the ID of the current resource if you have Friendly URLs switched on.

            <?php
            $uri = $_GET[$modx->getOption('request_param_alias')];
            $resourceId = 0;
            if (array_key_exists($uri, $modx->aliasMap)) {
                $resourceId = $modx->aliasMap[$uri];
            };
            
            return $resourceId;


            If you're not using friendly URLs, try switching $_GET[$modx->getOption('request_param_alias')] for $_GET['q'] (untested but may work based on comments I've seen).

            MODX - so many ways to achieve any given thing. Love it! [ed. note: jcdm last edited this post 7 years, 1 month ago.]
            • It would be
              $_GET[$modx->getOption('request_param_id')]
              when friendly urls are not being used.