如何在树枝模板视图中书写?

时间:2017-12-08 10:45:51

标签: symfony drupal twig

Drupal 7的PHP代码:

<?php foreach ($rows as $row_number => $columns): ?>
    <?php foreach ($columns as $column_number => $item): ?>
        <?php print $item; ?>
    <?php endforeach; ?>
<?php endforeach; ?>

我写了这个,但我在Drupal 8中收到错误。代码:

{% foreach row_number, columns in rows %} 
    {% foreach column_number, item in columns %} 
        {{ item }} 
    {% endforeach %} 
{% endforeach %}

1 个答案:

答案 0 :(得分:1)

在树枝中使用for代替foreach

{% for row_number, columns in rows %} 

    {% for column_number, item in columns %} 

        {{ item }}

    {% endfor %}

{% endfor %}