Pages ($pages)

The next big object you should know about, is the $pages variable. It contains every page of your site and you can browse it very fast and easy. The way you filter and search through it is highly inspired by jQuery, so if you are familiar with that you should get along very fast. If not, you are totally lost – just kidding :)

$pages->find($uri)

This is the most common way to search through all pages by uri to get a page object back. Take a look at the example:

Example A:

span class="st0">'about-us'// will echo "About us"      

Example B:

span class="st0">'projects/project-1'

" " 

$pages->active()

This is the same as the globally available $page variable. It will return the current page object. You should use $page instead.

$pages->findOpen()

Find the open page in a set. Read more about $page->isOpen here

$pages->findBy($key, $value)

This is a nice way to find a page by a specific key and value. Let's say the contact page has a field street:

content/contact/contact.txt

Street: Sesamestreet
----
City: New York
----
…

You could then get that page like this:

span class="st0">'street', 'Sesamestreet'

Pretty cool :)

$pages->findByUID($uid)

Find a page by UID. UID is the name of the folder without the prepended number. The UID of the "01-about-us" folder would be "about-us"

$pages->findByDirname($dirname)

While findByUID takes the name of the folder without the number in front, this one searches for the entire dirname.

$pages->findByTitle($title)

Well, that should be easy to get :)

$pages->first()

Find the first page in a set of pages

$pages->last()

Find the last page in a set of pages

$pages->count()

Count the number of pages in a set

 

or

 

$pages->visible()

Returns a set of visible pages. For example if you want to find all visible children of the current page, do it like this:

 

If you want to get all visible first level pages, do this:

 

$pages->countVisible()

Count all visible pages in a set of pages.

$pages->invisible()

Returns a set of invisible pages.

$pages->countInvisible()

Count all invisible pages in a set of pages.

$pages->without($uid)

Returns a set of pages without the page with the given UID

span class="st0">'project-1'

$pages->not($uid)

is a shortcut for $pages->without($uid) to have a more jquery way of doing this.

$pages->slice($offset, $limit)

If you want to get a subset of pages, use the slice method to set the offset and limit.

span class="co1">// get all children starting with the third one. 
// get five children starting with the third one.
// get five children starting with first one.          

$pages->limit($limit)

Limit the result of pages in a set.

span class="co1">// only get the first 5 pages (is equal to $pages->slice(0,5))

$pages->offset($offset)

Get a set of pages, starting with an offset.

span class="co1">// starting with the sixth element of a set (is equal to $pages->slice(5))

$pages->flip()

Returns a set of pages in reversed order. If you sort your folders with the appended numbers, it is sometimes easier to reverse the default sort so higher numbers will be returned first. For example if you build a blog and your article folders are named like this:

…you probably want to get a set of pages where 03-third-article is first. That's where $pages->flip() is just doing what you want.

$pages->sortBy($sort='title', $direction='asc')

Sort a set of pages by any field and direction:

span class="st0">'dirname', 'desc''title', 'desc''date', 'asc'

$pages->shuffle()

Returns the set of pages in random order

 

Pagination

Pagination sucks!! It's always a hassle to set that up right so Kirby implements a very nice way to paginate through a set of pages.

Here is how it is done:

First you call the paginate($limit) method on a set of pages. This will add a pagination object to the set. Set the limit to the number of pages you want to get per page.

 

Do something with that list of 10 pages


    
    
    
 

Add previous and next links

 

   
  "next"" "next
   

   
  "prev"" "previous
   

 

The pagination object

Here's a list of all available methods of the pagination object:

$list->pagination->page()

Returns the current page

$list->pagination->countPages()

Get the total number of pages of entries.

$list->pagination->hasPages()

Returns true if there's anything to paginate at all and false if not.

$list->pagination->countItems()

Return the total number of entries.

$list->pagination->pageURL($page)

Generate an url to a specific page of a list.

$list->pagination->firstPage()

Return the page number of the first page of a list.

$list->pagination->isFirstPage()

Checks if the current page is the first page

$list->pagination->firstPageURL()

Returns the url to the first page.

$list->pagination->lastPage()

Returns the page number of the last page of a list.

$list->pagination->isLastPage()

Checks if the current page is the last page

$list->pagination->lastPageURL()

Returns the url to the last page.

$list->pagination->prevPage()

Returns the page number of the previous page of a list.

$list->pagination->hasPrevPage()

Checks if there's a previous page

$list->pagination->prevPageURL()

Returns the url to the previous page.

$list->pagination->nextPage()

Returns the page number of the next page of a list.

$list->pagination->hasNextPage()

Checks if there's a next page

$list->pagination->nextPageURL()

Returns the url to the next page.