有点像doozy。我试图在模板中渲染表单,模板是包含在另一个模板中的模板。
在我的控制器中:
public function searchInvSumAction(Request $request)
{
$form = $this->createFormBuilder()
->add('fromdate','date', array(
'label' => 'From: ',
'widget' => 'single_text'
))
->add('todate','date', array(
'label' => 'To: ',
'widget' => 'single_text'
))
->add('generate','submit')
->getForm();
return $this->render('CIRBundle:Reports:index.html.twig', array(
'invsum' => $form->createView()
));
}
index.html.twig模板:
// codes........
<li>
<input type="radio" name="tabs" id="tab3">
<label for="tab3" class="tab">Inventory Summary</label>
<div id="tab-content3" class="tab-content animated fadeIn">
{{ include('CIRBundle:Reports:invsum.html.twig') }}
</div>
</li>
// more codes...
并在包含的模板上调用invsum.html.twig:
{{ form(invsum) }}
我收到错误消息:
Variable "invsum" does not exist in CIRBundle:Reports:invsum.html.twig at line 4
当我尝试将表单呈现到invsum.html.twig中时,我仍然得到相同的错误,即变量不存在。有什么帮助吗?
答案 0 :(得分:0)
您未将变量invsum
从index.html.twig
传递到invsum.html.twig
尝试
{{ include('CIRBundle:Reports:invsum.html.twig', {'invsum': invsum}) }}