Twig - 动态数组键 [英] Twig - Dynamic array key

查看:29
本文介绍了Twig - 动态数组键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在开发基于 Symfony 的工具.我正在迭代一系列配置设置.我想要实现的目标似乎很简单:

Currently working on a tool built on Symfony. I am iterating over an array of configuration settings. The thing I want to achieve seemed simple enough:

我正在尝试获得某个值.不过,其中一个键必须是动态的.下面是一个没有动态键的工作示例.

I am trying to obtain a certain value. One of the keys has to be dynamic though. Below is a working example without the key being dynamic.

{% set id = tmod_config.content_1.id %}

(content_1"是有问题的关键)

("content_1" being the key in question)

键末尾的数字必须是动态的.我已经尝试了几件事,但无法实现这一目标.到目前为止,我可以访问动态值,只需将其转换为功能键即可.

The number at the end of the key has to be dynamic. I have tried a couple of things but wasn't able to achieve this. Up to this point I have access to the dynamic value, it just needs to be turned into a functioning key.

有什么建议吗?

问题解决了!检查答案

推荐答案

因为它是一个数组,你可以使用任何一种..

As it is an array you could use either..

{% set id = tmod_config[content_1].id %}

{% set id = attribute(tmod_config, content_1).id %}

这篇关于Twig - 动态数组键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆