Hi all.
I have a simple snippet which shows a chunk based on a date range. (for example, for free shipping in January).
Currently in the snippet I hard code the dates like so:
<?php
$today = date('Y-m-d');
// Adjust the date ranges as needed
$timedChunk = 'freeShippingJan2025';
$standardBannerChunk = 'normalBanner';
if ($today >= '2024-12-22' && $today <= '2025-01-31') {
return $modx->getChunk($timedChunk);
} else {
return $modx->getChunk($standardBannerChunk);
}
But I felt it would be easier to manage by setting the dates in client config. So I set up the settings, and replaced them in my snippet like so:
<?php
$today = date('Y-m-d');
// Adjust the date ranges as needed
$timedChunk = 'freeShippingJan2025';
$standardBannerChunk = 'normalBanner';
if ($today >= '[[++dateBannerStarts]]' && $today <= '[[++dateBannerEnds]]') {
return $modx->getChunk($timedChunk);
} else {
return $modx->getChunk($standardBannerChunk);
}
But this doesn’t work.
For sanity, I also included my client config settings in the template itself to check they are working like so:
[[++dateBannerStarts]]
and the output is exactly as expected:
2024-12-22
So I don’t understand why the date value doesn’t trigger the chunk within the snippet?
I’m sure there’s a simple explanation!
I would love to understand it!
Thanks
Andy