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

Answered Output filter

    • 11121
    • 79 Posts
    Quote from: Bruno17 at Feb 03, 2016, 01:08 PM
    can't see anything, why this shouldn't work, then.

    How do you call the snippet?
    Did you try to place the placholders directly after the snippet-call?

    [[IMAGE_PATH]] [[+photo1]]

    I call this inside a tpl for a getresources call.
      • 4172
      • 5,888 Posts
      are you trying to get the images from the iterated resources?
      Then you will need to pass the resource-id to your snippet and get the TV of that resource.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 11121
        • 79 Posts
        Quote from: Bruno17 at Feb 03, 2016, 04:48 PM
        are you trying to get the images from the iterated resources?
        Then you will need to pass the resource-id to your snippet and get the TV of that resource.

        The code below is working for single resource:

        $values = explode(',',$modx->resource->getTVValue('IMAGE'));
        $first = $values[0];
        $second = $values[1];
        $third = $values[2];
        $modx->setPlaceholder('path1',$first);
        $modx->setPlaceholder('path2',$second);
        $modx->setPlaceholder('path3',$third);
        return '';


        Bruno also the code you suggested, which is much more elegant, is working too. A small typo error was the problem.

        $values = explode(',',$modx->resource->getTVValue('IMAGE'));
        $i = 1;
        foreach ($values as $value){
            $modx->setPlaceholder('path'.$i,$value);
            $i++;
        }
         
        return '';


        For itaretad resources (getResource) no luck yet.
        • discuss.answer
          • 4172
          • 5,888 Posts
          <?php
          
          $docid = $modx->getOption('docid',$scriptProperties,$modx->resource->get('id'));
          if ($resource = $modx->getObject('modResource',$docid)){
              $values = explode(',',$resource->getTVValue('IMAGE'));
              $i = 1;
              foreach ($values as $value){
                  $modx->setPlaceholder('path'.$i,$value);
                  $i++;
              }    
          }
            
          return '';
          


          and call it with

          &docid=`[[+id]]`
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 11121
            • 79 Posts
            Quote from: Bruno17 at Feb 04, 2016, 07:43 PM
            <!--?php
            
            $docid = $modx--->getOption('docid',$scriptProperties,$modx->resource->get('id'));
            if ($resource = $modx->getObject('modResource',$docid)){
                $values = explode(',',$resource->getTVValue('IMAGE'));
                $i = 1;
                foreach ($values as $value){
                    $modx->setPlaceholder('path'.$i,$value);
                    $i++;
                }    
            }
              
            return '';
            


            and call it with

            &docid=`[[+id]]`


            It works, thank you!!! [ed. note: gordonas last edited this post 8 years, 1 month ago.]
              • 11121
              • 79 Posts
              Quote from: Bruno17 at Feb 04, 2016, 07:43 PM
              <!--?php
              
              $docid = $modx--->getOption('docid',$scriptProperties,$modx->resource->get('id'));
              if ($resource = $modx->getObject('modResource',$docid)){
                  $values = explode(',',$resource->getTVValue('IMAGE'));
                  $i = 1;
                  foreach ($values as $value){
                      $modx->setPlaceholder('path'.$i,$value);
                      $i++;
                  }    
              }
                
              return '';
              


              and call it with

              &docid=`[[+id]]`


              Bruno only a bug with getresources. With the above code, values are submitting to the database correctly. But when getresources populates results, caches them even though I call everything uncached. See attachment.

              Image 1 is correct. Image 2 doesn't exist. There is an empty field there, but getresources displays previous data. Stuck here...