I would like to show a content element (within a template) between two dates. I’ve setup two date TVs and a current time/date PHP snippet however I can’t seem to trigger a PHX greater or less than string.
[+phx:if=`[*myfromDate*]`:gt=`[!currentDateSnippet!]`:then=`{{showChunk}}`+]
Are there any existing snippets available to address my desired addition?
Thanks, Martin.
-
☆ A M B ☆
- 24,524 Posts
You probably need to convert those dates into timestamps before trying to compare them.
Hi, Thanks for the feedback.
The element I’m looking to show between a set dates is a special offer price, the date only applies to the price deduction and not the doc publish from to parameters which would remain unaffected.
I hope this helps.
Any further suggestions would be very welcome
You could use something like this snippet without using phx (with a little modding to fit your purpose)
<?php
$output ='';
// the name of the date TV
$date_tv_name ='my_date_tv';
// name of the chunk
$show_chunk_name ='FormLogin';
// get the tv date info
$tv_output = $modx->getTemplateVarOutput(array($date_tv_name));
// make the TV date info into a timestamp
$date_output = $modx->ToTimeStamp($tv_output[$date_tv_name]);
// get current timestamp
$current_time = time();
// if date tv is greater than current time, show chunk
if($date_output > $current_time){
$output .='{{'.$show_chunk_name.'}}';
}
return $output;
?>