We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    http://modxcms.com/forums/index.php/topic,17180.0.html -> If you viewed that thread, this is the final result of that plugin idea.
    http://tales.rpgplanet.gamespy.com/snippet_test.php -> Demostration of this plugin --- this will be removed once it goes final.


    Anyways, this plugin is used to output a selected chunk’s data on a specified page. It uses a ?selctedname=chunkname URL scheme. This is useful for MODx CMS installs that are used on RPG websites (if the person puts their item/enemy/etc. in chunks like I did), or for general use, like having a new window with a contact form, etc. It also gives off an error if you put in the wrong URL. smiley

    I put this here, because there’s one thing I’m trying to pin down before this can be used by the general public...

    I know people may not want item as their selectedname field, so I tried putting in a config option to change it, which was based off how some of the other plugins I have installed do it. But when I tried putting in $urlParam in the place of item in the code, it gave the error message. Anyone know what I was doing wrong?

    Big thanks to ZAP and sirlancelot for helping me with this plugin. And now for the code...

    <?php
    // --------------------
    // SNIPPET: PopUpChunk
    // --------------------
    // Version: 0.1 Beta
    // Date: August 19th, 2007
    // Plugin By: Soshite on ModXCMS.com ([email protected])
    // A big thanks goes to...
    // - ZAP (MODx CMS Testing Q&A)
    // - sirlancelot (MODx CMS Coding)
    //
    // This snippet is designed to output a selected chunk's data in another page, after
    // someone clicks a given link. This is useful for when you need a small piece
    // of information, like a conatct form, but can't have it inside the original page.
    
    // CONFIGURATION SETTINGS
    
        // $urlParam [string]
        // This field defaults as "item", but you can change the
        // field here...
        // (isset($urlParam)) ? $urlParam : $urlParam = 'item';
    
    // END CONFIG SETTINGS --- DO NOT EDIT BELOW THIS LINE
    
    $chunk = $_GET['item']; // Grab the url parameter
    
    $chunkText = $modx->getChunk($chunk); // get the item from the chunk
    
    if (!$chunkText) $chunkText = '<b>Error</b>: Cannot locate chunk. Please check to see if the URL specified was valid.'; // :(
    
    return $chunkText; // Output to parser
    ?>
      My Snippets
      -> PopUpChunk v1.0
      • 27376
      • 576 Posts
      Looking great! smiley
      Quote from: Soshite at Aug 19, 2007, 07:42 AM

      I know people may not want item as their selectedname field, so I tried putting in a config option to change it, which was based off how some of the other plugins I have installed do it. But when I tried putting in $urlParam in the place of item in the code, it gave the error message. Anyone know what I was doing wrong?
      Here’s what you need to do:
      <?php
      
      $urlParam = isset($urlParam) ? $urlParam : 'item'; // default to 'item'
      
      $chunk = $_GET[$urlParam]; // Grab the url parameter
      
      $chunkText = $modx->getChunk($chunk); // get the item from the chunk
      
      if (!$chunkText) $chunkText = '<b>Error</b>: Cannot locate chunk. Please check to see if the URL specified was valid.'; // :(
      
      return $chunkText; // Output to parser
      Common MODx practice is to use [tt]isset()[/tt] and the ternary operator for snippet parameters. This makes it easy to determine what the parameter will "default" to.
        • 28033
        • 925 Posts
        Thanks...I knew I was missing something.

        I’ll test that out tommorow morning, and hopefully, with no errors/bugs, submit it to the Resource Listings as well. smiley
          My Snippets
          -> PopUpChunk v1.0
          • 28033
          • 925 Posts
          UPDATE

          http://modxcms.com/forums/index.php?topic=17582

          The "final" version of the snippet has been submitted to the Resource Listing. A big thanks to all of you who helped me develop this snippet. ^.^
            My Snippets
            -> PopUpChunk v1.0