We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    I am trying to build a link on the fly. Originally I had a snippet calling a getChunk method and passing the values to the chunk. Inside the chunk was a line of code like:

    [[~123? &rec=`[[+rec]]` &ab=`[[+ab]]`]]

    This worked great to build my url, but I decided that a chunk was limiting the way I could display the data on the page, as I wanted to display data outside the area defined for my content. I then changed my snippet to place everything into placeholders. When I did this, I moved everything from my chunk to the resource, adding a prefix to all my tags. Everything looked great until I tried to use my link. It did not work. This code:

    [[~123? &rec=`[[+prefix.rec]]` &ab=`[[+prefix.ab]]`]]

    created a url that looked something like:

    mypage?rec=%5B%5B%2Bprefix.rec%5D%5D&ab=%5B%5B%2Bprefix.ab%5D%5D

    From my testing, I have found that passing values to placeholders, and then trying to reference those placeholders inside a call to make a url, the values are not passed. I have created a workaround by passing the placeholders to a snippet, which then runs makeurl. However, it would be nice to know if this is a bug that will be fixed in the near future, or if this is expected behavior?
      • 3749
      • 24,544 Posts
      I think it's expected behavior but I'm not sure.

      It would probably be faster and more reliable to do it yourself in a custom snippet something like this:


      [[!MyUrl?  &docId=`123` &rec=`[[+prefix.rec]]` &ab=`[[+prefix.ab]]`]]



      <?php
      /*MyUrl snippet */
      $fields = array (
          'rec' => $scriptProperties['rec'],
          'ab' => $scriptProperties['ab']
      }
      
      return $modx->makeUrl($scriptProperties['docId'], "", $fields, "full");
      


        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
        • 37286
        • 160 Posts
        I actually wanted something that was reusable ( ie, multiple parameters for any page ), so I went with this:

        [[!MyUrl?  &resource=`123` &rec=`[[+prefix.rec]]` &ab=`[[+prefix.ab]]`]]
        


        <?php
        $resource= (int)$modx->getOption('resource',$scriptProperties,0);
        unset($scriptProperties['resource']);
        $url= $modx->makeUrl($resource,'',$scriptProperties);
        
        return $url;
        
          • 3749
          • 24,544 Posts
          Glad you got it solved. The default ID is a nice addition. wink


            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