Part of the EllisLab Network

Blog & News

Lisa Wess
Director of Community Services

Dissecting the Default Templates: Paginate Variable Pair

As we move down the template, we can see the light at the end of the {exp:weblog:entries} tag: the Pagination code. In a case where you have many entries in a weblog, and want to give people the ability to go through all of those entries, you probably will not want them all on one page.  But we need some access to those, so how about being able to go to the second page of the list, or the third, and on down the line?  This is where paginating comes in handy.

Shall we just jump right in?

The default template gives us this ability, and we see it right here in our index template:

{paginate}
<div class="paginate">
<
span class="pagecount">Page {current_page} of {total_pages} pages</span>  {pagination_links}
</div>
{/paginate}

Now, this is a variable pair, which we can see from the opening and closing {paginate} and {/paginate} tags, respectively.  So, how about we search for paginate, which brings us to Weblog Entry and Comment Pagination.  We can see there that there are two ways to paginate, but because we have this code in front of us, we know which way we’re looking at by comparing it to the documentation.

We also know, from the previous article on variables that items like {current_page} are variables that output the appropriate information for the page, as they are in the context of the Paginate tag pair.

There is an additional note to make when discussing Pagination.  The pagination code will create the necessary HTML before the first post, after the last post, or in both places as determined by the paginate= parameter; by default, it shows after the last entry.

Paginate works this way because it belongs to the set of entries currently output, and not to the individual entries themselves, and so there is special handling to make sure that the paginate links only appear the correct number of times and in the appropriate place in the rendered page.

Now, let’s skip to the last line that we’ll discuss for today.

{/exp:weblog:entries}

This, of course, closes off the weblog entries tag pair.  If you do not include this ending line, then the variables that you used above will render unparsed on the page; so this is a very important line to include in the template.

Well folks, we have completed the basic review of one of the most powerful tags in ExpressionEngine.  We’ll delve into some of the other tags, which are great for creating navigation to your archives, as we go further down the template in future articles.