We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42377
    • 14 Posts
    Using Revo 2.2.6

    I'm trying to find the URL needed to link back to the parent document from within a template applied to the Symlink.

    I've tried:

    <a href="[[~[[+parent]]]]">Link</a>  and
    <a href="[~[*parent*]~]">Link</a>


    I'm sure it's something simple that I'm missing, but just wasted about 45 minutes searching for the answer online.

    Thanks a million!
    Jamie
    • Do you mean the resource that the symlink is taken from?
        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
        • 42377
        • 14 Posts
        Quote from: sottwell at Jun 28, 2013, 07:59 PM
        Do you mean the resource that the symlink is taken from?

        Yepper! Thanks sottwell.
        • Hm. Have been doing some experimenting with symlinks. They behave rather oddly. I had expected that just the content field from the resource linked to would be inserted. The content of the symlink in the database is the ID you're linking to, but it's proving very difficult to get at that value.
            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
          • Sometimes the pagetitle, longtitle, description, introtext will be the same as the resource being linked to, sometimes it will be that of the symlink resource. Having the various tags uncached seems to help.

            A snippet to get the class_key always returns modDocument, even though it's obviously a modSymLink. A snippet to get the content directly from the database will return the linked resource's content.
            $content = $modx->resource->get('content');
              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
              • 42377
              • 14 Posts
              Quote from: sottwell at Jun 28, 2013, 08:52 PM
              Sometimes the pagetitle, longtitle, description, introtext will be the same as the resource being linked to, sometimes it will be that of the symlink resource. Having the various tags uncached seems to help.

              A snippet to get the class_key always returns modDocument, even though it's obviously a modSymLink. A snippet to get the content directly from the database will return the linked resource's content.
              $content = $modx->resource->get('content');

              Thank you for your efforts. It's nice to know I'm not crazy, that it wasn't as simple as I thought it should be. I will play with this and report back on how it works out.
              • I can get the actual content (the ID of the linked resource) using @SELECT binding for a TV - but only if I specify the actual ID of the symlink:
                @SELECT content from modx_site_content where id = 4

                So you could use such a TV but it would have to be edited for each symlink to use its own ID. [[*id]] didn't work there at all, nor did a snippet to get the ID.
                  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
                • Got it! Use a snippet:

                  $thisId = $modx->resource->get('id');
                  $result = $modx->query("SELECT * FROM modx_site_content WHERE id=$thisId");
                  if (!is_object($result)) {
                     return 'No result!';
                  }
                  else {
                     $row = $result->fetch(PDO::FETCH_ASSOC);
                     return 'Result:' . $row['content'];
                  }
                  return;


                  the raw xPDO query doesn't process symlink content the way that the modResource object does.

                  http://rtfm.modx.com/display/xPDO20/xPDO.query
                    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
                    • 42377
                    • 14 Posts
                    You are brilliant! Thank you. Copying this straight into a snippet, removing the output prefix of Result: gave me exactly what I needed (just the id number of the parent document) to create the back-links dynamically. Sorry for the delayed reply - I put this project to the side for the weekend and just came back to it. I really really really really REALLY appreciate your help.

                    -Jamie

                    Quote from: sottwell at Jun 29, 2013, 05:32 AM
                    Got it! Use a snippet:

                    $thisId = $modx->resource->get('id');
                    $result = $modx->query("SELECT * FROM modx_site_content WHERE id=$thisId");
                    if (!is_object($result)) {
                       return 'No result!';
                    }
                    else {
                       $row = $result->fetch(PDO::FETCH_ASSOC);
                       return 'Result:' . $row['content'];
                    }
                    return;


                    the raw xPDO query doesn't process symlink content the way that the modResource object does.

                    http://rtfm.modx.com/display/xPDO20/xPDO.query
                    [ed. note: jamesb last edited this post 10 years, 10 months ago.]