We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17412
    • 270 Posts
    Hi. I have a little php script to switch CSS styles based on the server time, it goes a little something like this:

    <?php
        $hour = date('H');
        if($h < 8 || $h >= 20) {
          $css = 'background: transparent url(/assets/templates/main/images/bg_container_night.gif) no-repeat 100% 5px';
        } elseif ($h >=17) {
          $css = 'background: transparent url(/assets/templates/main/images/bg_container_cloud.gif) no-repeat 100% 5px';
        } else {
          $css = 'background: transparent url(/assets/templates/main/images/bg_container.gif) no-repeat 100% 5px';
        }
        echo '<style type="text/css">'.$css.'</style>';
    ?>


    I know I cannot just whack that into the template - could anyone give me some advice on how to get that into my template?

    Thanks.
    • Place the code into a snippet and call it uncached (eg. [!snippet!]) in the template where you want the output to be.

      Make sure you strip out the ’<?php’ and ’?>’ in the snippet code else it will throw an error.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 17412
        • 270 Posts
        sweet! thanks.