symfony - 无法在树枝文件中打印键和值
问题描述
我无法在 for 循环中获取键和值我的要求应该类似于标题 - 描述
我无法获得标题和描述中的值
(
[product_benefit] => Array(
[0] => Array
(
[description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
[title] => Ipsum Lorem
)
[1] => Array
(
[description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
[title] => Ipsum Lorem
)
[2] => Array
(
[description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
[title] => Ipsum Lorem
)
[3] => Array
(
[description] => Lorem Ipsum is simply dummy text of the printing and typesetting industry.
[title] => Entertainment
)
)
{% if product.product_benefit is not null %}
<ul class="manual-list">
{% for row in product.product_benefit %}
{% for slug, item in row %}
<li><b>{{ item.title - item.description }}</b></li>
{% endfor %}
{% endfor %}
</ul>
解决方案
您遇到的第一个问题是您的输出现在减去两个字符串,切换到{{ foo }} - {{ bar}}
或{{ foo ~'-'~ bar }}
读取数据:
- 如果你想
keys
直接在你的代码中使用,那么你的第二个for
已经过时了。
{% for row in product.product_description %}
{{ row.title }} - {{ row.description }}
{% endfor %}
- 如果要保持键动态,则需要第二个 for 循环,但不再使用文字
{% for row in product.product_description %}
{% for key, value in row %}
{{ key }} = {{ value }}
{% endfor %}
{% endfor %}
推荐阅读
- javascript - 自动滚动到页面右侧(取决于图像的大小)
- python - python 3中关于@property的一些疑问
- operating-system - 如何对照 PT 条目检查页码?
- string - Bash:一个、另一个或两个的外壳字符串匹配
- macos - 想知道如何在文件名增加时删除文件?
- gcloud - Google cloud_sql_proxy 让我的连接保持活跃
- spring - Spring cloud sleuth 未将密钥附加到 Hibernate 查询日志
- python - Psycopg2 将日期字符串转换为前一天
- laravel - 多个搜索字段结果的分页 laravel 5.8
- java - Java Stream - 过滤列表时的NullPointExeption