2016-02-26 60 views
1

this page documentatation,下面的代碼應該很好地工作:包含聲明如何在Twig中工作?

<div class="paginator"> 
    <strong>pagina</strong> 
    <!-- Loop here --> 
    <a class="current "href="#">1</a> 
    <!-- End loop --> 
    <!-- This tag is only an example: --><a href="#">2</a> 
    {% include 'pagination.html.twig' with { 
     currentFilters: { myFilter: filtervariables }, 
     currentPage: page, 
     paginationPath: "myroute", 
     lastPage: totalPages, 
     showAlwaysFirstAndLast: true 
    } only %} 
</div> 

但是它返回:

Unable to find template "pagination.html.twig" in something.html.twig at line (number).

的頁面是在同一個文件夾中pagination.html.twig,所以我似乎無法到了解發生了什麼。有沒有人能解釋我發生了什麼?

在此先感謝。

回答

3

首先,它是更好地使用include函數,而不是標籤({{ include('pagination.html.twig, {}) }}),因爲標籤已經過時,它會在某個點(http://twig.sensiolabs.org/doc/functions/include.html

然後被刪除,您必須使用全合格路徑名稱到模板。如果您的pagination.html.twig位於app/Resources/foo/bar文件夾中,則必須編寫foo/bar/pagination.html.twig。如果是在src/Bundle/FooBundle/Resources/views/bar文件夾,你必須寫@Foo/bar/pagination.html.twig

+0

應該只是返回'somefolder/template.html.twig'而不是'views/somefolder/template.htm.twig' – Barrosy

+0

啊,不知道該標籤將被棄用,無法找到關於它的一個筆記http://twig.sensiolabs.org/doc/tags/include.html – Rvanlaak

+0

嗯,其實,它不會被棄用。但它應該是;)(標籤不應輸出內容) – lyrixx

0

嘗試使用軟件包的名稱,並查看目錄名稱等設置路徑:

{{ include('AppBundle:Default:pagination.html.twig', {}) }} 

其中「的appbundle」是一個包名稱包含視圖與「默認」有pagination.html.twig文件的目錄。

+0

AppBundle:默認值:pagination.html.twig是引用視圖的舊方法。看到我的回答爲現代的方式 – lyrixx

+0

謝謝lyrixx,其實我不知道這是舊的方式。 – 2016-02-26 15:37:10