We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36762
    • 45 Posts
    Is there a way I can design different looks for a site at different holidays and have it automatically switch based on a date?

    So for example I would like to have designs for New Years, Valentines Day, 4th of July, Halloween, Thanksgiving, Christmas, etc. Then a week before each holiday have it switch all the pages to the holiday specific design (for Christmas maybe the whole month). As soon as the holiday is over, have the site revert back the normal design.

    Can anyone think of a good way to handle this?
      • 4172
      • 5,888 Posts
      you could create some CSS-Resources under a specified parent with a pub/unpub-date and call that resources into your head as your CSS and have a default CSS if no special CSS is active.

      the idea, untested:
      [[!getResources:default=`[[$defaultCSS]]`?
      &parent=`yourCssParent`
      &limit=`1`
      &tpl=`cssTpl`
      ]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        A snippet could be used to determine the date, and at certain dates return a .css filename, like xmas.css or val.css.

        Then use the snippet tags in your template head when linking to the .css files.

        I just saw a post describing pretty much this same thing yesterday or the day before.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 38290
          • 712 Posts
          Quote from: sottwell at Dec 05, 2013, 07:59 PM
          A snippet could be used to determine the date, and at certain dates return a .css filename, like xmas.css or val.css.

          Then use the snippet tags in your template head when linking to the .css files.

          I just saw a post describing pretty much this same thing yesterday or the day before.

          I think this is a good approach.
            jpdevries
            • 3749
            • 24,544 Posts
            No need to involve getResources. You can just do something like this in a custom snippet in the template:

            function getHoliday() {
               /* date calculation here */
            
               /* return name of holiday (e.g., 'easter', 'thanksgiving', 'christmas', 'none') */
            }
            
            
            $holiday = getHoliday();
            
            $modx->regClientCss(MODX_ASSETS_PATH . 'css/holidays/' . $holiday . 'css');
            
            return '';


            There's also a "Seasons" snippet here that you could use by changing the dates and using regClientCss() as above instead of using chunks: http://bobsguides.com/blog.html/2013/11/21/change-your-modx-wed-site-with-the-seasons/


              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
              • 4041
              • 788 Posts
              Heres another basic snippet example you could extend for different months, for revo usage change the snippet tags accordingly:

              /*  display_switcher
              
              usage: add snippet call to the head of your template(s)
              [!display_switcher!]
              
              */
              
              // server time offset in hours
              // evo could use $modx->config['server_time_offset']
              $ds['time_offset'] =-5;
              
              // create array of days in july which will use changed output
              $july_days = array( '1', '2', '3', '4' );
              
              // set up the default output
              $output ='
              <link href="assets/templates/template/default_style.css" rel="stylesheet" type="text/css" media="screen" />
              ';
              
              
              // calculate current time
              $ds['time'] = time() + $ds['time_offset'] * 3600;
              
              // create an array of time details
              $time_details = getdate( $ds['time'] );
              
              // switch between the months ( 1 - 12 )
              switch( $time_details['mon'] ){
              
                  // note the case should be the month number ( 1 - 12 )
                  case '4':
                  
                      // july example
                      if( in_array( $time_details['mday'], $july_days ) ){
                      
                          // if today is in the $july_days array change
                          // the $output
                          $output ='
                          <link href="assets/templates/template/july.css" rel="stylesheet" type="text/css" media="screen" />
                          ';
                          
                          // we could also set placeholders or grab chunks
                      }
                      
                  break;
              
                  default: '';
              }
              
              return $output;
              
                xforum
                http://frsbuilders.net (under construction) forum for evolution