gpt4 book ai didi

php - 如何访问 Twig 中的动态变量名?

转载 作者:IT王子 更新时间:2023-10-29 00:07:54 26 4
gpt4 key购买 nike

我在 Twig 中有一些变量,比如

placeholder1
placeholder2
placeholderx

为了调用它们,我循环遍历对象数组“invoices”

{% for invoices as invoice %}
need to display here the placeholder followed by the invoice id number
{{ placeholedr1 }}

最佳答案

我只是遇到了同样的问题 - 使用第一个答案并经过一些额外的研究发现 {{ attribute(_context, 'placeholder'~invoice.id) }} 应该有效(_context 是按名称包含所有对象的全局上下文对象)

关于php - 如何访问 Twig 中的动态变量名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24697313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com