我试图检查服务器日期和时间,以与资源的日期电视相比较,但当我试图检查IF语句时,我总是得到空白页,这就是我需要的。
我有一个像这样的片段
<?php
function getDatetimeNow() {
$tz_object = new DateTimeZone('Europe/Belgrade');
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
return $datetime->format('Y'-m'-d' h:i:s');
}
$currentDate = getDatetimeNow();
$dtA = new DateTime($currentDate);
$dtB = new DateTime($date);
if ( $dtA > $dtB ) {
$active = 0;
return $active;
}
else {
$active = 1;
return $active;
}
但是在页面上,如果我尝试这样做
[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]]
我得到1或0基于电视值*DatumIsteka,一切都工作正常,但当我尝试比较像这样
[[!If?
&subject=`[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]]`
&operator=`equals`
&operand=`0`
&then=`<script>
$("#tab3").html("<p>U Pripremi</p>");
</script>`
]]
我有白页的资源??有什么问题,任何帮助都会很好:)
将操作符更改为not equal并将操作数更改为1 - modx电视实际上不存在,除非它们被填充[即使它们有默认定义],如果电视未被填充,您可能会在代码片段中获得空值或错误。
或
返回你的返回值
if ( $dtA > $dtB ) {
$active = 0;
}
else {
$active = 1;
}
echo $active;
return;
如果可能有问题解释返回值为布尔值与字符串?
您还可以更改代码片段以检索当前资源datumistka值,然后使用输出修饰符。
或者像这样:
<?php
function getDatetimeNow() {
$tz_object = new DateTimeZone('Europe/Belgrade');
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
return $datetime->format('Y'-m'-d' h:i:s');
}
$currentDate = getDatetimeNow();
$dtA = new DateTime($currentDate);
$date = $modx->resource->getTVValue('DatumIsteka');
$dtB = new DateTime($date);
if ( $dtA > $dtB ) {
$active = $modx->getChunk('chunkName');
// chunkName = <script>$("#tab3").html("<p>U Pripremi</p>");</script>
}
else {
$active = 1;
}
echo $active; // you have to echo it if you are passing a string
return;