Barrosy
Barrosy

Reputation: 1457

How does include statement work in Twig?

According to this page documentatation, the following code should work fine:

<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>

However it returns:

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

The page is in the same folder as the pagination.html.twig so I can't seem to understand what's happening. Is there anyone that can explain me what is happening?

Thanks in advance.

Upvotes: 1

Views: 1659

Answers (2)

user5974427
user5974427

Reputation:

Try to set path using bundle name and view directory name etc:

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

where 'AppBundle' is a bundle name contains view with 'Default' directory having pagination.html.twig file.

Upvotes: 0

lyrixx
lyrixx

Reputation: 371

First, it's better to use the include function and not the tag ({{ include('pagination.html.twig, {}) }}), because the tag is deprecated and it will be removed at some point (http://twig.sensiolabs.org/doc/functions/include.html)

Then, you have to use the full qualified path name to the template. if your pagination.html.twig is in in the app/Resources/foo/bar folder, you have to write foo/bar/pagination.html.twig. If it's in the src/Bundle/FooBundle/Resources/views/bar folder, you have to write @Foo/bar/pagination.html.twig

Upvotes: 3

Related Questions