We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49560
    • 28 Posts
    Simple example:
    I have 3 pictures for a Gallery saved in a MIGX TV.
    Now I want to count how many entrys there are inside the TV.

    Why?
    If there is 1 picture I want to show it as a regular image.
    If there are 2 or more pictures I want to display the Gallery.

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

    [ed. note: alex.gr last edited this post 11 years, 10 months ago.]
      Alex G - Application Development Apprentice | New MODX User
      codeblick media
    • discuss.answer
      • 4172
      • 5,888 Posts
      I think, I would create a wrapper-snippet, which runs getImageList internally

      <?php
      
      $images = $modx->fromJson($modx->getOption('images', $scriptProperties, ''));
      $output = '';
      
      if (is_array($images) && count($images) > 0) {
      
          if (count($images) > 1) {
              $scriptProperties['wrapperTpl'] = $galleryWrapperTpl;
              $scriptProperties['tpl'] = $galleryTpl;
          } else {
              $scriptProperties['wrapperTpl'] = $imageWrapperTpl;
              $scriptProperties['tpl'] = $imageTpl;
          }
          $output = $modx->runSnippet('getImageList', $scriptProperties);
      }
      
      return $output;


      call it this way with all getImageList - properties + the created properties:

      [[yourSnippet?
      &galleryWrapperTpl=`yourGalleryWrapperTpl`
      &galleryTpl=`yourGalleryTpl`
      &imageWrapperTpl=`yourImageWrapperTpl`
      &imageTpl=`yourImageTpl`
      &images=`[[*yourMigxTV]]`
      &tvname=`yourMigxTV`
      ]]


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 49560
        • 28 Posts
        Sweet! You're really fast, I'll try it in a bit and let you know if everything works alright. smiley
          Alex G - Application Development Apprentice | New MODX User
          codeblick media
          • 49560
          • 28 Posts
          I've tried it but I might not understand it correctly, thats what my templates look like:

          MIGX TV: teaser
          Fields: image, title

          [[snippetNameHere?
              &galleryWrapperTpl=`galleryWrapperTpl`
              &galleryTpl=`galleryTpl`
              &imageWrapperTpl=`imageWrapperTpl`
              &imageTpl=`imageTpl`
              &images=`image`
              &tvname=`teaser`
          ]]


          galleryWrapperTpl
          
          <div>
              <ul>
                  [[+galleryTpl]]
              </ul>
          </div>
          

          galleryTpl
          
          <li>
              <img src="[[+image]]" alt="[[+title]]" />
          </li>
          

          imageWrapperTpl
          
          <div>
              [[+imageTpl]]
          </div>
          

          imageTpl
          
          <img src="[[+image]]" alt="[[+title]]" />
          
            Alex G - Application Development Apprentice | New MODX User
            codeblick media
            • 4172
            • 5,888 Posts
            the wrapperTpl has only one placeholder with the name [[+output]]

            <div>
                <ul>
                    [[+output]]
                </ul>
            </div>
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 49560
              • 28 Posts
              Alright you got me a little bit confused here. I've now changed both the wrapped placeholders to "[[+output]]".
                Alex G - Application Development Apprentice | New MODX User
                codeblick media
                • 4172
                • 5,888 Posts
                your snippet should be called like that, if your MIGX - TV has the name 'teaser'

                [[snippetNameHere?
                    &galleryWrapperTpl=`galleryWrapperTpl`
                    &galleryTpl=`galleryTpl`
                    &imageWrapperTpl=`imageWrapperTpl`
                    &imageTpl=`imageTpl`
                    &images=`[[*teaser]]`
                    &tvname=`teaser`
                ]]
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 49560
                  • 28 Posts
                  Oh perfect! That was my mistake smiley
                  Again: Thanks a lot Bruno! smiley
                    Alex G - Application Development Apprentice | New MODX User
                    codeblick media