Twig / PHP / Symfony嵌套错误 - 嵌套级别太深

时间:2016-04-21 09:48:27

标签: php symfony loops twig

我有一个(非常大的)twig html模板,在那里我显示一个表并循环遍历行:

{% for assignment in assignments %}
   ...
   {% if assignment.zip.contractor1 is not null %}
       {% for priceEK in assignment.zip.contractor1.pricecontractor %}
           {% if priceEK.zip == assignment.zip %}
               {% set bookDates = date(assignment.start|date).diff(assignment.end).days + 1 %}
               {% set priceDay = 0 %}
               {% set priceSide = 0 %}
               {% if bookDates > 1 %}
                   {% set priceDay = priceEK.priceDay * (bookDates - 1) %}
                   {% set priceSide = priceEK.priceAdd * (bookDates) %}
               {% endif %}
               {% if assignment.meter == 15 %}
                   {{ (priceEK.price15 + priceDay + priceSide)|number_format(2) }}€
               {% elseif assignment.meter == 20 %}
                   {{ (priceEK.price20 + priceDay + priceSide)|number_format(2) }}€
               {% else %}
                   {{ (priceEK.price25 + priceDay + priceSide)|number_format(2) }}€
               {% endif %}
           {% endif %}
       {% endfor %}
    {%endif %}

现在这就像一个魅力IF,assignment.zip.contractor1 is not null只是真实的一次。如果在循环assignments时第二次出现这种情况,则会在我的日志中出现以下错误:

  

错误:嵌套级别太深 - 递归依赖?

我认为这可能是一个复杂的问题,如果不知道数据库关系,请随时告诉我需要进一步的信息(以及如何在此处插入),我会相应更新。

//编辑也许有办法重置'嵌套的(priceEK)? {% set priceEK = null %}虽然没有效果......

// EDIT2:发现......否则,如HERE所述,将所有==更改为is same as()。现在我可以得到第二个循环。如果我有第三个,Firefox崩溃并想调试脚本......

//编辑:好的,找到了解决方案......也许这对其他人有帮助:

{% for pc in  assignment.zip.pricecontractor %}
    {% if pc.contractor is same as(assignment.zip.contractor1) %}
        {% set bookDates = date(assignment.start|date).diff(assignment.end).days + 1 %}
        {% set priceDay = 0 %}
        {% set priceSide = 0 %}
        {% if bookDates > 1 %}
            {% set priceDay = pc.priceDay * (bookDates - 1) %}
            {% set priceSide = pc.priceAdd * (bookDates) %}
        {% endif %}
        {% if assignment.meter is same as(15) %}
            {{ (pc.price15 + priceDay + priceSide)|number_format(2) }}€
        {% elseif assignment.meter is same as(20) %}
            {{ (pc.price20 + priceDay + priceSide)|number_format(2) }}€
        {% else %}
            {{ (pc.price25 + priceDay + priceSide)|number_format(2) }}€
        {% endif %}
    {% endif %}
{% endfor %}

0 个答案:

没有答案