2014-01-30 121 views
0

我是新來的Symfony2在某些部分struked文件如何呈現在樹枝

我的問題是需要鏈接到一個單獨的頁面時,我的一些按鈕點擊,我的網址鏈接到頁面,但在頁字段不顯示

//controller(Action function) 
public function displayAction(Request $request){ 
    if($request->isXmlHttpRequest()){ 
     $photos = new TcPhotos(); 
     $photos_form = $this->createForm(new PhotoType(), $photos); 
     $response = new JsonResponse(); 
     $response->setData(array('content' => $this->renderView('TcPhotoBundle:Default:display.html.twig',array('form' => $photos_form->createView())))); 
     return $response; 
    }else{ 
     $response = new JsonResponse(); 
     $response->setData(array('content' => 'something went wrong')); 
     return $response; 
    } 
} 

//view.html.twig 
<div><a href="#!{{ path('tc_photo_display') }}">more .....</a></div> 


//root 
tc_photo_display: 
pattern: /display 
defaults: { _controller: "TcPhotoBundle:Default:display" }  

請幫助我更好的解決方案,我只是需要當我點擊更多view.html頁

+0

請提供您的display.twig文件,其中包含哪些數據包含$ photos變量? – hizbul25

回答

0

可以render控制器的任何與此動作鏈接,顯示頁面樹枝模板中的語法:

{{ render(controller('AcmeArticleBundle:Article:recentArticles', { 
    'max': 3 
})) }} 

或者使用include爲根本,包括從任何其他模板的模板:

{{ include(
    'AcmeArticleBundle:Article:articleDetails.html.twig', 
    { 'article': article } 
) }} 

要閱讀這篇Including other Templates將是有用的爲您服務。

+0

事情是我無法得到該目標頁面的值,如果我給包括也不會採取 – harshamullangi

+0

也許嘗試使用「服務」與樹枝模板注入依賴於它 –