Change Your MODX Web Site with the Seasons

A long time ago in MODX Evolution, I had a client who wanted to show photos related to the current season and offer four different seasonal coupons. I thought I’d provide an updated version of the snippet for people who want to do something similar.

This snippet allow you to automatically produce seasonal changes on your web site. It can be used to simply display the name of the current season or to pull in chunks that "seasonalize" the site in various ways. It can be used multiple times on the same page. If you’re using the chunk version, you can create four chunks called summer, fall, winter, and spring (these are the default chunk names). Optionally, you can send the names of the four chunks as properties.


This version will return just the name of the season:

[code language=”html”]
[[!Season? &nameOnly=`1`]]

This one will return the content of the appropriate chunk if the chunks are called summer, fall, winter, and spring:

[code language=”html”]

This version sets the names of the chunks to use for each season:

[code language=”html”]

You could use this snippet to change the CSS with the seasons by putting the path to a different CSS file in each parameter and using the snippet call in your template where the CSS file is specified.

Using an image reference, it could be used to change an image or background image with the seasons.

The Snippet

Paste this code into a snippet called Season and save it.

[code language=”php”]
/* Season snippet */

if (! function_exists(‘season’)) {
function season() {
$limits = array(
‘/12/21’ => ‘winter’,
‘/09/21’ => ‘fall’,
‘/06/21’ => ‘summer’,
‘/03/21’ => ‘spring’,
‘/01/01’ => ‘winter’
$adate = date("M d Y"); /* set $adate to today */

foreach ($limits AS $key => $value) {
$limit = date("Y") . $key;
if (strtotime($adate) >= strtotime($limit)) {
return $value;

$summerChunk = $modx->getOption(‘summerChunk’, $scriptProperties, ‘summer’);
$fallChunk = $modx->getOption(‘fallChunk’, $scriptProperties, ‘fall’);
$winterChunk = $modx->getOption(‘winterChunk’, $scriptProperties, ‘winter’);
$springChunk = $modx->getOption(‘springChunk’, $scriptProperties, ‘spring’);

$nameOnly = $modx->getOption(‘nameOnly’, $scriptProperties, false);

/* Get the name of the current season */
$season = season();

/* Figure out what to return */
if (!empty($nameOnly)) {
/* Return just the season name */
$output = $season;
} else {
/* Return the content of the appropriate chunk */
$output = $modx->getChunk(${$season . ‘Chunk’});
return $output;


You can change the season names wherever they appear in the code, and if you’re using chunks, change the names of your chunks accordingly or just send their names in the snippet properties. Be sure to change all of them and preserve the case of each season. You don’t need to change the date formatting, since the date is never displayed and only digits are used for the calculation.

The date ranges are in the form /month/day and correspond to the official seasons in the USA. You may wish to change them for other locales.

If want to use the snippet on a multi-language site, you can create lexicon files. You’ll need to send an &language property in the snippet tag with the two-letter language code and add these lines just below the function in order to load the appropriate lexicon file:

[code language=”php”]
$language = $modx->getOption(‘language’, $scriptProperties, ‘en’);
$modx->setOption(‘cultureKey’, $language);

Change the line that returns just the season name to:

[code language=”php”]
$output = $modx->lexicon($season);

Then, in the lexicon file (say at, core/components/season/lexicon/fr/, do this:

[code language=”php”]
$_lang[‘spring’] = ‘printemps’;
$_lang[‘winter’] = ‘hiver’;
/* etc. */


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , | Posted under MODX, MODX | RSS 2.0

Author Spotlight

Bob Ray

Bob Ray is the author of MODX: The Official Guide and over 30 MODX add-on components. He hosts Bob's Guides, a source of valuable information for MODX users, and has been very active in the MODX Forums with over 19,000 posts.

One Comment on Change Your MODX Web Site with the Seasons

  1. says:

    Hey there! Someone in my Facebook group shared this website with us so I
    came to look it over. I’m definitely enjoying the information.
    I’m book-marking and will be tweeting this to my followers!
    Great blog and fantastic style and design.

Leave a Reply

Your email address will not be published. Required fields are marked *