We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38547
    • 98 Posts
    I have having an odd issue with snippet which is designed to output some images having most if its html stripped.

    If I run the snippet on a basic php page outside of modx its works fine. But when run as a snippet on a page template I should get images inside a table, so i get the opening <table tag with the closing > missing the the first <tr> tag and nothing else.

    The snippet is pulling images from a coppermine image script.

    I am using Revo 2.26 the snippet code loos like this

    <?php
      include "./coppermine/cpmfetch/cpmfetch.php";
      $objCpm = new cpm("./coppermine/cpmfetch/cpmfetch_config.php");
      
      $objCpm->cpm_viewLastAddedMedia(5,2, $options=array('imagewidth' => '40px'));
      $objCpm->cpm_close();
      ?>


    Does anyone have any ideas.

    Many thanks [ed. note: ianman last edited this post 11 years, 1 month ago.]
      • 3749
      • 24,544 Posts
      Snippet tags are replaced by whatever the snippet returns, and your snippet isn't returning anything.

      I suspect that the cpm class is using echo or print to output it's data. Generally, you want to aggregate the output by replacing echo or print with:
      $output .= 'something';

      Then put this at the end of the snippet:
      return $output;

      As an alternative, you can open an output buffer at the beginning of the snippet with ob_start() and get/flush its content at the end before returning the buffer contents with
      return ob_get_clean();

      The second method has not always worked for me, though it might be easier to implement in your case than aggregating the output.

      I should mention that if the cmp class works by dropping in and out of PHP (with multiple <?php tags), it will have to be completely rewritten to work with MODX.
        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
        • 38547
        • 98 Posts
        Thanks Bob

        I understand little about php but that class is just used to send some parameters to the cpmfetch.php file which gets included, the only thing I know if I put that code onto a php page outside of MODx it pulls in the data fine with all the table html tags, right now it does output the images and does everything else minus the html tags but sounds like its not a simple fix in fact I am using on the right column this page http://www.sudburymcc.co.uk minus some of the html tags but exactly the same code can be seen working on this page outside of modx with html tags http://www.sudburymcc.co.uk/cpmTest.php

        Thanks anyway for the reply

        Ian