简体   繁体   English

将循环从 php 转换为 twig

[英]Convert Looping from php to twig

I want to change the command from php to twig:我想将命令从 php 更改为 twig:

<?php for($__i = 0; $__i < sizeof($s_opts); $__i++) { ?>

<option value="<?php echo $s_opts[$__i]['id']; ?>"><?php echo $s_opts[$__i]['name']; ?></option> 

<?php } ?>

Here's one way of doing this这是执行此操作的一种方法

{% for opt in s_opts %}
    <option value="{{ opt.id }}">{{ opt.name }}</option> 
{% endfor %}

https://twig.symfony.com/doc/3.x/tags/for.html https://twig.symfony.com/doc/3.x/tags/for.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM