2012-10-06 27 views
2

是否可以为Symfony 2.0中的某个动作分配两个不同的模板?在下面的代码中,我想用两个不同的模板呈现IF部分和ELSE部分。一个Symfony 2.0控制器 - 带两个不同模板的动作

/** 
* 
* @Route("/", name="search") 
* @Template("Bundle:Search:search.html.twig") 
*/ 
public function indexAction() 
{ 
    if ($searchText == null) { 

     return array('form' => $form->createView(), 'form2' => $form2->createView()); 

    } else { 

     return array('applicants' => $appCount, 'pagination' => $pagination, 'form' => $form->createView(),'form2' => $form2->createView()); 
    } 
} 

回答

4

你不能这样做,与@Template注释,但您可以手动渲染每个:

if ($someCondition) { 
    return $this->render('Bundle:Controller:template.html.twig', array(
     'some' => $thing, 
    ); 
} 

return $this->render('Bundle:Controller:another.html.twig', array(
    'another' => $thing, 
); 
相关问题