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

    I’m using a modified version of "Picture and thumbnails on same page". All the code is in this chunk:

    <div class="gmgalerie">
    [!MaxiGallery? &pictureTpl=`mgPicture` &display=`pictureview`!]
    <div id="scroller">
        <img src="assets/templates/own/img/hoch.gif" alt="hoch" id="zurueck" onmouseover="startScroll(-1);" onmouseout="stopScroll();"/>
        <div id="ausschnitt">
    [!MaxiGallery? &galleryPictureTpl=`mgGalleryPicture` &galleryOuterTpl=`tplGmDetailsOuter` &js=`mgJs` &manageButtonTpl=`noManageButton`!]
    </div>
    <img src="assets/templates/own/img/runter.gif" alt="runter" id="weiter" onmouseover="startScroll(1);" onmouseout="stopScroll();"/>
    </div>
    </div>


    As you can see, there is some code around the picture and the thumbs for layouting. The chunk is "called" in my template. It works fine as long as there are pictures in the gallery. But in some cases, the gallery is empty and will stay empty (at least for a while). On these pages, the chunk must not be output. Otherwise, the surrounding code will show, but without images. That is wrong an looks faulty.

    How can I test if the gallery for the current document has pictures and output the cunk only if the number is not zero?

    Thanks for any ideas
    Martin
      • 7923
      • 4,213 Posts
      Do a custom galleryOuterTpl that prints out just the number of pictures in the gallery, eg. your template would be simply: [+maxigallery.picscount+]

      Then use phx conditional in your chunk to decide wether to print it or not:

      [+phx:if=`[!MaxiGallery? &galleryOuterTpl=`yourchunkname`]`:gt=`0`:then=`

      the above chunk content here...

      `+]

      But of course this will create alot of overhead as it runs whole maxigallery to just get the picture count and then runs it again if it needs to display images..

      It would be better to code a separate snippet for this that queries maxigallery db table.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 10313
        • 375 Posts
        Thanks for the input. I wonder if I could do it with appropriate outer templates. The only problem I see straightaway is the [tt]<div class="gmgalerie">[/tt] around it all. But that would be no problem, I think. I’ll give it a try. I think, that would be the slightest solution.

        Edit: This approach does not work. The OuterTpl ist output, even if the gallery is empty. I’ll try and code a snippet that counts the images.
          • 7923
          • 4,213 Posts
          Well did you check what [+maxigallery.picscount+] returns when the gallery is empty?

          Also possibly you cannot use :gt in PHx to compare the value that maxigallery returns.. you could check what the snippet call actually returns when the gallery is empty and then use :isnot PHx comparison.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 10313
            • 375 Posts
            Sorry, no I did not try your first proposal. Because of the huge overload.
              • 10313
              • 375 Posts
              This is my solution:

              snippet [tt]mgCountImg[/tt]:
              <?php
              $gid = isset($gallery)?$gallery:$modx->documentIdentifier;
              $table = $modx->getFullTableName("maxigallery");
              $rs = $modx->db->query("select count(ID) as anzahl from $table where gal_id=$gid");
              $anz = $modx->db->getColumn("anzahl", $rs);
              return $anz[0];
              ?>


              And finally
              [+phx:if=`[[mgCountImg]]`:gt=`0`:then=`{{gmDetailGalerie}}`:else=``+]