We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27160
    • 50 Posts
    How can I use one template for different galleries on different pages?
      Linda Jenkinson
      • 19369
      • 1,098 Posts
      Hi shyflower, I am not sure with so little information about your needs, but I think that you could create children resources to your gallery page. Here is a example

      Home(1)
      News(2)
      Gallery(3)
         Gallery 01(4)
         Gallery 02(5) 
         Gallery 03(6) 
         Gallery 04(7)  
      Contact(8)


      then, you can put a Ditto call inside Gallery(3)

      [!Ditto? &parents=`3` &orderBy=`createdon DESC` &display=`100` &total=`100` &tpl=`ditto-gallery` !]


      Hope this helps.
        • 27160
        • 50 Posts
        I have a template called smGallery. I need to use it for (at least) two documents, each of which will show different images. From the directions for MAXIGALLERY, I have created a container "My Galleries"(ID 59) which has two children -- call them Gallery A (ID 60) and Gallery B (ID 61).

        I have tried to create a template variable that will call the galleries from the template, but it doesn’t show the images. It only shows the code:

        <p>[!MaxiGallery? &display=`embedded` &embedtype=`slimbox` 
        &pics_per_row=`1` &max_thumb_size=`200` &max_pic_size=`0` !]</p>


        If I put this Ditto Call into ID 59, how will this tell the database which of the two child galleries to display in the document?

        Just now I have downloaded the PHx in hopes that something there will show me what to do.
          Linda Jenkinson
          • 27160
          • 50 Posts
          The PHx thing didn’t work. It just threw a bunch of parse errors. Right now, I’ve duplicated the template so that the correct galleries display on each of the two documents, but I would really prefer only one instance of the template if possible.
            Linda Jenkinson
            • 19369
            • 1,098 Posts
            I see your point, I think that I have a solution for you. I’ll explain it with an example:

            First, here is my structure:
            Home(1)
            News(2)
            Gallery one(3)
            Gallery two(4)
            Contact(5)

            So, I need two different ditto call for two gallery and I want to use only one template. Now...
            1)I create a snippet with name snippet-swap and I put inside this code:

            <?php
            $docid = $modx->documentIdentifier;
             switch($docid) {
            
            case 3: 
            return "{{gallery-one}}";
             break;
            
            case 4: 
            return "{{gallery-two}}";
             break;
            
            default: 
            return "[*content*]";
             break;
             }
            ?>
            


            2) I create two chunks, one named gallery-one, one named gallery-two, inside these chunks I put the ditto call for the gallery.

            3) I call the snippet from the template
            {{header}}
            [[snippet-swap]]
            {{footer}}
            


            Basically, the "case 3" is the ID Page, and in the snippet means that when you go to page Gallery one, it returns the chunk gallery-one, when you go to Gallery two, it returns gallery-two, as a default it will return [*content*]. Obviously you can modify it, it depends on your needs. This is just a example of what you could do to avoid multiple template (and multiple mistakes!)

            I use this snippet to make multilanguage websites using just 1 template.

            Hope that this helps
              • 27160
              • 50 Posts
              Thank you! I will certainly give it a try and let you know if it works!
                Linda Jenkinson
                • 19369
                • 1,098 Posts
                ok smiley