簡體   English   中英

使用Twig和Form Builder在Symfony 3.4中生成具有變量名的表單行

[英]Generating form rows with variable names in symfony 3.4 with twig and form builder

使用symfony 3.4(php)

我有一個表單,可以使用與客戶端相關的屬性來編輯當前用戶的用戶配置文件。 因此,我生成了一個繼承自Symfony\\Component\\Form\\AbstractType的UserType Symfony\\Component\\Form\\AbstractType ,並根據客戶端添加了具有EventListener的屬性:

$form->add('ca-' . $attribute->getId(), TextType::class, array('label' => $attribute->getAttributeName() . ':'));

現在如何在樹枝模板中為此生成行? 應該是這樣的

{{ form_row(form['ca-' . attribute.id]) }}

但似乎我無法將整數attribute.id與句點綁定。 有沒有辦法在這里訪問這個變量? 使用以下代碼可以很好地訪問屬性address

{{ form_row(form.address) }}

謝謝

嘗試:

{{ form_row(form['ca-' ~ attribute.id]) }}

要在樹枝中連接字符串和變量,只需使用~

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM