We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16217
    • 4 Posts
    I found a great image gallery (http://www.e2interactive.com/e2_photo_gallery/demo.php) that I want to use on my Modx site and I need some help in figuring out what code to put where. My first attempt was to put all the "PHP" code in a snippet, and then put all the HTML in a chunk, but it’s not working.

    I don’t know if I’m supposed to call the snippet from the chunck, the chunck from the snippet, or both from the template.

    Any ideas? I’m not looking for anyone to do it for me - I just need a push in the right direction.

    Thank you so much in advance for any and all help!

      • 7231
      • 4,205 Posts
      You need to take a look at the API. You can either load the chunk from the snippet or include the presenational code within the snippet.

      Check out this wiki post on creating snippets, it has some help. Also check out the setplaceholder and getchunk api functions.

      http://wiki.modxcms.com/index.php/API:getChunk
      http://wiki.modxcms.com/index.php/API:setPlaceholder

      Also sometimes just copying the php into a snippet will not work, some modifications may be needed. One thing to remember is that the snippet needs to output or return something.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 16217
        • 4 Posts
        The code I’m trying to integrate is really nothing more than two "require once" statements and a few echos. The echos make sense - but what about the "require once" statements? Those don’t seem to work well in a snippet. Am I not using them right? Is there a different way to use them in a snippet, or do they not belong in a snippet?

        Thanks again for your help.
          • 10449
          • 956 Posts
          require / include calls work fine in modx snippets - you just have to make sure you’re using correct paths. Both absolute and relative paths should work.
            • 26435
            • 1,193 Posts
            I use this all the time"

            <?php
            require_once $modx->config[’base_path’].’assets/snippets/mysnippet/myinclude.php’;
            ?>

            -sD-
            Dr. Scotty Delicious, DFPA.
              Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
              All of the above... in no specific order.


              I send pointless little messages
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              It’s also a good way to allow config files in a snippet instead of a long string of parameters in the snippet call. Just check if the $include is set (&include=`file`), and include that file if it is, or a sane default if it isn’t. Wayfinder and I believe Ditto work that way now. Very convenient.
                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