We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25330
    • 14 Posts
    I am wondering if there is a way already built into modx that could add the current url path as a parameter when I link to a different resource. I have tried several different things and show an example here of trying to add a snippet which had javascript in it.

    <a href="[[~101?url=`[[$currentUrl]]`]]">Go Here</a>

    Using just the [[*id]] worked with putting the id in there but doesn’t help with passing the full alias path. But seeing that it did pass the id made me think that there was a way already in MODx to accomplish this url passing.
    <a href="[[~101?url=`[[*id]]`]]">Go Here</a>
      • 33968
      • 863 Posts
      You can use your example to pass the current page id:
      <a href="[[~101?url=`[[*id]]`]]">Go Here</a>
      

      This is much neater than passing the full url.

      And assuming you want to pass the parameter to a snippet on the receiving page, you can use this to build the url:
      <?php
      $url = $_GET['url'];
      return $modx->makeUrl($url);
      

      See makeUrl for more details.
        • 25330
        • 14 Posts
        Perfect, thanks for pointing me to the makeUrl too. Here is what I used that gave me exactly what I was looking for.

        Link
        <a href="[[~101?url=`[[*id]]`">Go Here</a>
        


        Snippet
        <?php
        $url = $_GET['url'];
        return $modx->makeUrl($url, '', '', 'full');