duanguochong0397 2016-08-24 05:33
浏览 15

Modx IF返回空白页面

I am trying to check server date and time to compate with date TV of resource, but i always get blank page when I try to check in IF statment, here is what i need.

I have snippet like this

<?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;
}

But when on page if i try like this

[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]]

I got 1 or 0 based on TV value *DatumIsteka, all is working ok, but when i try to compare like this

[[!If?
    &subject=`[[!CheckCurrentDate? &date=`[[*DatumIsteka]]`]]`
    &operator=`equals`
    &operand=`0`
    &then=`<script>
    $("#tab3").html("<p>U Pripremi</p>");
    </script>`
    ]]

I got white page of resource?? What can be the problem, any help will be nice :)

  • 写回答

1条回答 默认 最新

  • doufu1950 2016-08-24 14:18
    关注

    change your operator to not equal and your operand to 1 - modx TVs don't actually exist unless they are populated [even if they have a default defined] you may be getting a null value or error in your snippet if the TV is not populated.

    OR

    echo your return value,

    if ( $dtA > $dtB ) {
      $active = 0;
    }
    else {
      $active = 1;
    }
    
    echo $active;
    
    return; 
    

    IF may be having issues interpreting the return values as boolean vs. string?

    You can also change your snippet to retrieve the current resources DatumIsteka value and then use output modifiers.

    or something like this:

    <?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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图