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 :)
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:
span class="st0">'about-us'// will echo "About us"
This is the same as the globally available
$page variable. It will return the current page object. You should use
Find the open page in a set. Read more about $page->isOpen here
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:
Street: Sesamestreet ---- City: New York ---- …
You could then get that page like this:
span class="st0">'street', 'Sesamestreet'
Pretty cool :)
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"
While findByUID takes the name of the folder without the number in front, this one searches for the entire dirname.
Well, that should be easy to get :)
Find the first page in a set of pages
Find the last page in a set of pages
Count the number of pages in a set
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:
Count all visible pages in a set of pages.
Returns a set of invisible pages.
Count all invisible pages in a set of pages.
Returns a set of pages without the page with the given UID
is a shortcut for $pages->without($uid) to have a more jquery way of doing this.
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.
Limit the result of pages in a set.
span class="co1">// only get the first 5 pages (is equal to $pages->slice(0,5))
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))
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.
Sort a set of pages by any field and direction:
span class="st0">'dirname', 'desc''title', 'desc''date', 'asc'
Returns the set of pages in random order
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.
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
Here's a list of all available methods of the pagination object:
Returns the current page
Get the total number of pages of entries.
Returns true if there's anything to paginate at all and false if not.
Return the total number of entries.
Generate an url to a specific page of a list.
Return the page number of the first page of a list.
Checks if the current page is the first page
Returns the url to the first page.
Returns the page number of the last page of a list.
Checks if the current page is the last page
Returns the url to the last page.
Returns the page number of the previous page of a list.
Checks if there's a previous page
Returns the url to the previous page.
Returns the page number of the next page of a list.
Checks if there's a next page
Returns the url to the next page.