We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20135
    • 188 Posts
    Hi,

    I have written a snippet that outputs a link to files uploaded directly to a database table. However, if I use the snippet more than once on the page, all the links on that page become the same as the last snippet listed on the page. Does anyone have an idea how I can separate the processing of these snippets so that I can use the snippet more than once on the page?

    Below is the snippet code I’m using:

    Snippet Call in content:
    [!secDownload? &secID=`2` &secTag=`test2` &secTitle=`test2`!]
    


    Snippet Code
    <?php
    // add $_GET['fid'] to url
    $curr_Addr = $modx_config['base_path']."assets/modules/secFileManager/";
    $connector = $_GET ? "&" : "?";
    $secAddr = $curr_Addr."includes/downloadFiles.inc.php?fid=".$secID;
    
    $modx->setPlaceholder('secAddr', $secAddr);
    $modx->setPlaceholder('secTitle', $secTitle);
    $modx->setPlaceholder('secTag', $secTag);
    
    return $modx->getChunk('secLink');
    ?>
    


    Chunk
    <a href="#" title="[+secTitle+]" onclick="window.open('[+secAddr+]','Secure_Download','height=150,width=150')">[+secTag+]</a>
    


    Please ask any questions you like, I’ll be happy to add any info you need. Thanks in advance.
      • 4041
      • 788 Posts
      Try this:

      <?php
      // add $_GET['fid'] to url
      $curr_Addr = $modx_config['base_path']."assets/modules/secFileManager/";
      $connector = $_GET ? "&" : "?";
      $secAddr = $curr_Addr."includes/downloadFiles.inc.php?fid=".$secID;
      
      $modx->setPlaceholder('secAddr', $secAddr);
      $modx->setPlaceholder('secTitle', $secTitle);
      $modx->setPlaceholder('secTag', $secTag);
      
      return $modx->getChunk('secLink');
      
      unset($secAddr);
      unset($secTitle);
      unset($secTag);
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 20135
        • 188 Posts
        Thanks Breezer, but no joy.

        I’m thinking that because each snippet is calling the same chunk, this could be where the problem lies. Any thoughts? Is there anyway of using the same snippet but with different output?

        Update:
        It is the chunk that is the problem here. If I break the rules and use the snippet to output the text, the links work great.

        How can I do this with 1 chunk so that I don’t break the rules?
          • 4041
          • 788 Posts
          Maybe this one will work better:

          <?php
          // add $_GET['fid'] to url
          $curr_Addr = $modx_config['base_path']."assets/modules/secFileManager/";
          $connector = $_GET ? "&" : "?";
          $secAddr = $curr_Addr."includes/downloadFiles.inc.php?fid=".$secID;
          $output ='';
          
          $chunkarray = array(
                              secAddr  => $secAddr,
                              secTitle => $secTitle,
                              secTag   => $secTag);
          
          $output .= $modx->parseChunk('secLink', $chunkarray, '[+', '+]');
          unset($chunkarray);
          
          return $output;
          ?>
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 20135
            • 188 Posts
            Hi,

            That looks to have done it. Will keep testing, hopefully it stands up.

            Thanks Breezer! smiley