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

    Just wondering if it’s possible to create a snippet that will call another snippet based on a day of the week? Something along the lines of:

    <?php
    $d=date("D");
    if ($d=="Fri")
      echo "[[snippit1]]";
    else
      echo "[[snippet2]]";
    ?>
      • 3749
      • 24,544 Posts
      Yes, but you can’t use MODX tags in snippet code. PHP doesn’t know what to do with them.

      You need to use something like this:

      <?php
      $output = $modx->runSnippet('SnippetName');
      
      
      return $output;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 15734
        • 70 Posts
        What I really want to do is display one gallery on friday and if any other day display another gallery. So this:

        <?php
        $d=date("D");
        if ($d=="Fri")
          $output = $modx->runSnippet('MaxiGallery? &gal_query_ids=`1` &display=`normal` &max_pic_size=`960x340` &galleryPictureTpl=`bannerImageTpl` &manage_target=`23` &galleryOuterTpl=`bannerOuterTpl`');
        
        return $output;
        else
            $output = $modx->runSnippet('MaxiGallery? &gal_query_ids=`2` &display=`normal` &max_pic_size=`960x340` &galleryPictureTpl=`bannerImageTpl` &manage_target=`23` &galleryOuterTpl=`bannerOuterTpl`');
        
        return $output;
        ?>
          • 3749
          • 24,544 Posts
          Looks good, but the snippet properties need to be in an array. Also, it’s partly a matter of coding style, but I would do it this way (note: no back-ticks -- only single quotes):
          <?php
          $d=date("D");
          
          $galleryId = ($d == 'Fri')? 1 : 2;
          
          $properties = array(
               'gal_query_ids' => $galleryId,  
               'display' => 'normal',  
               'max_pic_size' => '960x340', 
               'galleryPictureTpl' => 'bannerImageTpl', 
               'manage_target' => '23', 
               'galleryOuterTpl' => 'bannerOuterTpl',
          );
              
          $output = $modx->runSnippet('MaxiGallery, $properties);
          
          return $output;
          ?>



            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 15734
            • 70 Posts
            Awesome Bob. Thanks very much. I’ll give this a try in the morning.
              • 3749
              • 24,544 Posts
              Quote from: kevince52 at Aug 18, 2011, 07:01 PM

              Awesome Bob. Thanks very much. I’ll give this a try in the morning.

              Don’t thank me until it works. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 3749
                • 24,544 Posts
                BTW, you could also put the maxigallery tags in two separate chunks and use this:

                $d=date("D");
                $chunk = $d=="Fri"? 'Chunk1' : 'Chunk2';
                
                return $modx->getChunk($chunk);
                


                That might, or might not, make it easier to maintain.

                Another way to go (as long as I’m rambling) would be to use this:

                [[MaxiGallery? &gal_query_ids=`[!GetGallery!]` &display=`normal` &max_pic_size=`960x340` &galleryPictureTpl=`bannerImageTpl` &manage_target=`23` &galleryOuterTpl=`bannerOuterTpl`]]


                <?php
                /*GetGallery snippet */
                $d=date("D");
                return $d=="Fri"?  '1'  :  '2';
                


                That might be the fastest, but I’m not sure about the cache processing in Evo.

                In MODX, there’s almost never just one way to do something. wink
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 15734
                  • 70 Posts
                  Thanks for your help Bob. Your last solution was the one I went with. The only change I had to make was to call GetGallery cached.

                  Cheers and thanks for all the time you put in here.
                    • 3749
                    • 24,544 Posts
                    I’m glad it worked. Thanks for reporting back. cool
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting