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

    Re my previous post (#70), I have solved issue 2 with a bit of CSS, although the second caption is still positioned a line down for some reason...

    Still can’t get images to show up... :-(

    Cheers - Zaphodx
      • 16895
      • 87 Posts
      This extra is really going to need its own section. It’s absolutely awesome!

      I’ve been playing around with modifying the getImageList code to build a ’download’ section for a blog.

      I’ve set up a blog based closely on Shaun’s model and have used MIGX to set up a system where I can create a set of attachments/downloads for each post. I wanted to show every single download on the entire site on one page, but getImageList only supported a single value for $docid, so I’ve made some slight modifications to the code which, as far as I can see, work fine. The modified code takes &docids (which is a comma-separated list of resources to get the MIGX TVs from) as a parameter.

      You can use getResourcesTag or getResources to produce that list pretty easily: in my case I’m pulling the TVs from every post (within a certain set of parent resources) that has the tag ’download’ (you can set &tag in getResourcesTag, it’s just not documented).

      Here’s the changed code, if anyone finds it useful. I’m sure Bruno17 will be able to see 50 ways of making it better within about 10 seconds of diff-ing it, so I’m apprehensive about making a pull-request on the git repo wink

      <?php
      /**
       * getImageList
       *
       * Copyright 2009-2010 by Bruno Perner <[email protected]>
       *
       * getImageList is free software; you can redistribute it and/or modify it
       * under the terms of the GNU General Public License as published by the Free
       * Software Foundation; either version 2 of the License, or (at your option) any
       * later version.
       *
       * getImageList is distributed in the hope that it will be useful, but WITHOUT ANY
       * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
       * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
       *
       * You should have received a copy of the GNU General Public License along with
       * getImageList; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
       * Suite 330, Boston, MA 02111-1307 USA
       *
       * @package migx
       */
      /**
       * getImageList
       *
       * get Images from TV with custom-input-type imageList for MODx Revolution 2.0.
       *
       * @version 1.2
       * @author Bruno Perner <[email protected]>
       * @copyright Copyright © 2009-2010
       * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License
       * version 2 or (at your option) any later version.
       * @package migx
       */
      
      /*example: <ul>[[!getImageList? &tvname=`myTV`&tpl=`@CODE:<li>[[+idx]]<img src="[[+imageURL]]"/><p>[[+imageAlt]]</p></li>`]]</ul>*/
      /* get default properties */
      
      $docids = $modx->getOption('docids', $scriptProperties, $modx->resource->get('id'));
      
      $docids = explode(',', $docids);
      
      foreach($docids as $docid) {
      
      // initialise vars, if using property sets get those
      $tvname = $modx->getOption('tvname', $scriptProperties, '');
      $tpl = $modx->getOption('tpl', $scriptProperties, '');
      $outputvalue = $modx->getOption('value', $scriptProperties, '');
      $limit = $modx->getOption('limit', $scriptProperties, '0');
      $offset = $modx->getOption('offset', $scriptProperties, 0);
      $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
      $randomize = $modx->getOption('randomize', $scriptProperties, false);
      $preselectLimit = $modx->getOption('preselectLimit', $scriptProperties, 0); // when random preselect important images
      
      /*
      if (empty($tpl)) {
          return 'empty property: &tpl';
      }
      */
      if (!empty($tvname)) {
          if ($tv = $modx->getObject('modTemplateVar', array('name' => $tvname))) {
              $outputvalue = $tv->renderOutput($docid);
              /*
              *   get inputTvs 
              */
              $properties = $tv->get('input_properties');
              $properties = isset($properties['formtabs']) ? $properties : $tv->getProperties();
              $formtabs = $modx->fromJSON($properties['formtabs']);
              $inputTvs = array();
              if (is_array($formtabs)) {
                  foreach ($formtabs as $tab) {
                      if (isset($tab['fields'])) {
                          foreach ($tab['fields'] as $field) {
                              if (isset($field['inputTV'])) {
                                  $inputTvs[$field['field']] = $field['inputTV'];
                              }
                          }
                      }
                  }
              }
      
          }
      }
      
      if (empty($outputvalue)) {
          return '';
      }
      
      $items = $modx->fromJSON($outputvalue);
      $modx->setPlaceholder($totalVar, count($items));
      $output = '';
      if (substr($tpl, 0, 6) == "@FILE:") {
          $template = file_get_contents($modx->config['base_path'] . substr($tpl, 6));
      } else
          if (substr($tpl, 0, 6) == "@CODE:") {
              $template = substr($tpl, 6);
          } else
              if ($chunk = $modx->getObject('modChunk', array('name' => $tpl), true)) {
                  $template = $chunk->getContent();
              } else {
                  $template = false;
              }
      
              if (count($items) > 0) {
                  $items = $offset > 0 ? array_slice($items, $offset) : $items;
                  $count = count($items);
                  $limit = ($limit == 0 || $limit > $count) ? $count : $limit;
                  $preselectLimit = $preselectLimit > $count ? $count : $preselectLimit;
                  //preselect important items
                  if ($randomize && $preselectLimit > 0) {
                      $tempitems = array();
                      for ($i = 0; $i < $preselectLimit; $i++) {
                          $tempitems[] = $items[$i];
                          unset($items[$i]);
                      }
                      shuffle($items);
                      $items = array_merge($tempitems, $items);
                  }
      	  
                  $tempitems = array();
                  for ($i = 0; $i < $limit; $i++) {
                      $tempitems[] = $items[$i];
                  }
                  $items = $tempitems;
                  if ($randomize) {
                      shuffle($items);
                  }
      
      	    $idx = 0;
      	  
                  $output = "";
                  foreach ($items as $key => $item) {
                      $fields = array();
                      foreach ($item as $field => $value) {
                          if (isset($inputTvs[$field])) {
                              if ($tv = $modx->getObject('modTemplateVar', array('name' => $inputTvs[$field]))) {
                                  $tv->set('default_text', $value);
                                  $fields[$field] = $tv->renderOutput($docid);
                              }
                          } else {
                              $fields[$field] = $value;
                          }
                      }
                      $fields['_alt'] = $idx % 2;
                      $idx++;
                      $fields['_first'] = $idx == 1 ? true : '';
                      $fields['_last'] = $idx == $limit ? true : '';
                      $fields['idx'] = $idx;
                      $fields['docid'] = $docid;
                      if ($template) {
                          $chunk = $modx->newObject('modChunk');
                          $chunk->setCacheable(false);
                          $chunk->setContent($template);
                          $output .= $chunk->process($fields);
                      } else {
                          $output .= '<pre>' . print_r($fields, 1) . '</pre>';
                      }
                  }
                 $return .= $output;
              }
      }
      
      return $return;
      


      I went through and annotated the entire snippet line-by-line, so if you spot any errant comments that I’ve forgotten to remove here, mea culpa. If anyone wants a more detailed description of what I did, just ask and I’ll write it up properly.

      If someone wants to give me access to RTFM I’ll be happy to expand on the MIGX documentation that’s there at the moment.
        • 4172
        • 5,888 Posts
        Thanks legio_noctis.

        An alternativ way which produces the same result is to use getResources and the getImageList-snippet in the getResources-tpl with:

        [[!getImageList? &tvname=`myMIGXtv` &tpl=`myItemTpl` &docid=`[[+id]]`]]


        did you try that way?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 4172
          • 5,888 Posts
          Quote from: zaphodx at Jun 04, 2011, 11:07 AM

          Hi,

          Re my previous post (#70), I have solved issue 2 with a bit of CSS, although the second caption is still positioned a line down for some reason...

          Still can’t get images to show up... :-(

          Cheers - Zaphodx

          what is your output for your images? produced sourcecode from firebug?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 16895
            • 87 Posts
            I didn’t even think of that shocked

            So much simpler! And it doesn’t break half of the other features! I’m such a fool... laugh
              • 33379
              • 110 Posts
              Hi Bruno17,

              In the img tags it shows src="", i.e. there is no image name or path...

              Cheers - Zaphodx
                • 4172
                • 5,888 Posts
                whats the output when you use the TV directly without getImageList ?
                just with

                [[*myMIGXtv]]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 33379
                  • 110 Posts
                  Re: Post #70

                  If I call the MIGX TV directly I get this on the page:


                  [{"title":"The River Wye","description":"

                  The most beautiful river in the UK!!!

                  ","image":"pics/RiverWye01.jpg"}]


                  The middle line is rendered as per CSS, the first and last lines have no styling. I think this is to do with tinymce affecting the caption.

                  Cheers - Zaphodx
                    • 33379
                    • 110 Posts
                    More info re: post #70

                    If I code the image url into the myMIGXTpl it shows up on the page - so the image file and path are OK.

                    If I call [[*myMIGXtv]] directly the page shows this -

                    [{"title":"The River Wye","description":"

                    The most beautiful river in the UK!

                    ","image":"pics/RiverWye01.jpg"}]

                    - which shows the image path/name has been included in the output.

                    This is the myMIGXTpl chunk, all the TV placeholders except the [[+image]] work:

                    <div class="migxCell1">
                      <div class="migxThumb1"><a><img src="[[+image]]" height="100%" width="100%" alt="[[+title]]" /></a></div>
                      <div class="migxTextCell1">
                        <div class="migxHead1">[[+title]]</div>
                        <div class="migxCaption1">[[+description]]</div>
                      </div>
                      <div class="clearSpanCell0"></div>
                    </div>


                    This leads me to think that there is something wrong with the "image" TV. This is set up with "Input Type" set to "Image" and I have tried "Output Type" as both "Default" and "Image", I haven’t changed anything else, the Path & URL options are left at "NO", although I have tried various option with them to no avail.

                    Other than this image problem MIGX is working beautifully now, and will be one of the most useful addons to MODx, so any ideas on this would be most welcome!

                    Cheers - Zaphodx
                      • 4172
                      • 5,888 Posts
                      you should use output-type default. I think there is something wrong with your path-configs for the image-TV.

                      Can you get images with normal image-TVs? What I mean is, when you assign a normal image-TV without MIGX to your template and choose an image.
                      Do you get the image with this in your template or content:

                      <img src="[[*image]]"/>
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!

                      This discussion is closed to further replies. Keep calm and carry on.