【问题标题】:Twig current time between two times两次之间的树枝当前时间
【发布时间】:2017-04-27 13:10:33
【问题描述】:

我已经给出了两次(教义类型时间)并想检查当前时间是否在 for-if 循环中的这些时间之间。我使用来自树枝的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) &gt;= date()) 为假,但关闭为真。有人想解决这个问题吗?

【问题讨论】:

  • 你有错误吗??
  • 请贴出time.opening和time.closing的内容以及你当前的date()。

标签: php symfony twig


【解决方案1】:

为了监督起见,我会更改您的代码并拆分 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 %}

【讨论】:

    猜你喜欢
    • 2019-04-08
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多