We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11449
    • 28 Posts
    Hi, I'm currently trying to move one of my sites from Evolution to a fresh Revolution install. I have run into a little problem, my Evolution install has a small custum snippet that took the values of some TV's for images and formated them for placement in the HTML. I was able to hack this together with the help of someone who actualy knows PHP. But a simple copy and paste of it won't work in Revolution, so I was windering if any of you PHP savy and MODx gurus could help port it for me, because I don't really know how its doing what it is in evo and I have no clue how to reproduce the effect en Revo.

    I have 6 TV set up: Image1, Alt1, Link1, Image2, Alt2, Link2. They are image, text and URL TVs respectivly. The idea is that the user can set up to two images for each page that get added to an area of the site. The snippet took these TV values and formated them into corect HTML code. I don't understand how it works for both sets of images. Here is the snippet that works fine in Evo:

    <?php
    /* This exists thanks to Sam Washburns great patience with my stupidity in PHP */
    for($i=1;$i<=2;$i++){
        $image = $modx->documentObject['Image'.$i][1];
        $alt = $modx->documentObject['Alt'.$i][1];
        $url = $modx->documentObject['link'.$i][1];
        //var_dump($modx->documentObject);
        if (isset($image) && $image != "" ) {
         if (isset($url) && $url != "" ) {
           echo "<a href=\"{$url}\" title=\"{$alt}\" target=\"blank\" ><img src=\"{$image}\" alt=\"{$alt}\" /></a>";
         }
         else {
           echo "<img src=\"{$image}\" alt=\"{$alt}\" />";
         }
       }    
    }
    ?>


    From what I read "documentObject" has been depreciated. So I'm assuming a different method must be used, like "resource->get" or something, but I have no clue how to do it. If any of you could help with this I would be greatly appreciative, and if you need to know any other information let me know and I'll try dig it up.

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      something like this should work:

      <?php
      /* This exists thanks to Sam Washburns great patience with my stupidity in PHP */
      $output = '';
      for($i=1;$i<=2;$i++){
          $image = $modx->resource->getTvValue('Image'.$i);
          $alt = $modx->resource->getTvValue('Alt'.$i);
          $url = $modx->resource->getTvValue('link'.$i);
          //var_dump($modx->documentObject);
          if (!empty($image)) {
           if (!empty($url)) {
             $output .= "<a href=\"{$url}\" title=\"{$alt}\" target=\"blank\" ><img src=\"{$image}\" alt=\"{$alt}\" /></a>";
           }
           else {
             $output .= "<img src=\"{$image}\" alt=\"{$alt}\" />";
           }
         }   
      }
      
      return $output;
      ?>
      


      You can also try the MIGX-package, where you can add as many items as you want.
      Ok, not as many as you want, but a lot more than two. [ed. note: Bruno17 last edited this post 12 years, 2 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 11449
        • 28 Posts
        Thanks a ton man works great! MIGX looks really useful, will definitely use it for future projects!