[英]Spaceless does not want to work correctly in Symfony2 Twig Template
[英]Symfony: Loop does not work in twig template
我在存儲庫中創建了一個簡單的函數,並將其傳遞給這樣的控制器
控制器
...
public function repositoryAction() {
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('AppBundle:User')->findAllOrderedByName();
return $this->render('dashboard/repository.html.twig',array('user'=>$user));
}
與下面的代碼行
return $this->render('dashboard/repository.html.twig',array('user'=>$user));
我將數組傳遞給視圖。
這是樹枝模板中的循環
{% for user in profile %}
{{ profile.name }}
{% endfor %}
這是錯誤:
Variable "profile" does not exist in dashboard/repository.html.twig at line 44
我做錯了什么?
我認為你應該這樣做:
{% for profile in user %}
{{ profile.name }}
{% endfor %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.