templates
  • symfony
  • 2011-10-25 34 views 2 likes 
    2

    嫩枝模板開始,我有這樣的細枝模板:在Symfony2中

    {% block javascripts %} 
    
        {% javascripts '@AibFrontendBundle/Resources/public/js/update.js' %} 
         <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.js'></script> 
         <script src="{{ asset_url }}" type="text/javascript"></script> 
        {% endjavascripts %} 
    
    {% endblock %} 
    
    {% block content %} 
    <div id="contents"> 
        {{ contents|raw }} 
    </div> 
    
    <form action="{{ path('homepage') }}" method="post"> 
        {{ form_widget(form) }} 
        <input type="submit" /> 
    </form> 
    {% endblock %} 
    

    它正確顯示的內容。
    但是,如果我在開始時

    {% extends 'AibFrontendBundle::layout.html.twig' %} 
    

    添加下面這條線這表明layout.html.twig的內容,但我上面提到的內容沒有任何表現出更多..

    如何再次顯示內容?

    +1

    您能向我們展示您的layout.html.twig模板嗎? – greg0ire

    +0

    layout.html.twig裏面我寫了「aib」。 – ziiweb

    回答

    3

    layout.html.twig模板應包含類似於下面的內容:

    {% block content %}some optional default content here{% endblock %} 
    

    將由無論你在你的頁面模板供替換:

    mypage.html.twig:

    {% block content %} 
        This will appear in layout.html.twig where I specified the above block 
    {% endblock %} 
    

    查看Twig documentation瞭解更多詳情

    相關問題