Twig当前时间介于两次之间

时间:2016-12-12 16:02:31

标签: php symfony twig

我已经给过两次(教条类型时间)并且想要检查,如果当前时间在for-if-loop中这些时间之间。我用树枝上的Date compare。我的代码如下所示:

 {% for time in restaurant.openingHours if ((time.day == day) and (date(time.opening) <= date()) and (date(time.closing) >= date())) %}
    <span class="restaurant_info green"></span>
 {% else %}
    <span class="restaurant_info red"></span>
 {% endfor %}

最后一个条件(date(time.closing) >= date())为false但关闭为true。有人有想法解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

为了监督,我会更改你的代码并拆分forloop和if语句。为了检查出现了什么问题,只需将变量转储到树枝中,如下所示。

{%dump(time.opening)%}
{%dump(time.closing)%}
{%dump(date)%}

  {% for time in restaurant.openingHours  %}
        {%if ((time.day == day) and (date(time.opening) <= date()) and (date(time.closing) >= date()))%}
        <span class="restaurant_info green"></span>
         {% else %}
        <span class="restaurant_info red"></span>
        {%endif%}
     {% endfor %}