3
我現在有一個數組全預填充表單字段:循環通過拉從陣列信息嫩枝
$fields = array('title','first_name')
$info = array(
'title' => 'Mr',
'first_name' => 'John',
'last_name' => 'Smith'
)
正如你可以看到這個特定領域數組只包含標題和名字。
我的目標是循環訪問fields數組,並查看我的$info
數組中是否有任何信息用於預填充字段。
喜歡的東西:
foreach (fields as field) {
if (field is in $info array) {
echo the_field_value;
}
}
但很明顯在枝條,目前我有類似:
{% for key, field in context.contenttype.fields %}
{% if key in context.content|keys %} << is array
{{ key.value }}<< get the value of the field
{% endif %}
{% endfor %}
任何幫助是極大的讚賞。
非常感謝你的時間,我不知道如果信息[鍵]功能。 – jmack
嗨@jmack歡迎您! – Matteo