Handling pages
This page is about handling pages.
Table of contents
Reading configuration information from the config file
Sometimes, you want to read information from your configuration. This can be done using the Config
class.
Access this object using the DI
class:
<?php
use Kiwa\DI;
$config = DI::getConfig();
var_dump($config->getAllValues());
Searching and filtering pages
If you want to search for specific pages and/or filter them, Kiwa provides you the PageList
class. It works like this:
<?php
use Kiwa\Config\Page;
use Kiwa\Page\PageList;
$pageList = PageList::create()
->hasLanguageCode('de')
->isChildOf('blog')
;
/** @var Page $page */
foreach ($pageList as $page) {
var_dump($page->getPageTitle());
}
In this example, we are searching for all pages defined with a language code de
and being defined as child pages of the page blog
. The $pageList
contains then an array of Page
objects.
Available filters
Currently available filters are:
hasLanguageCode(string $languageCode)
isChild()
isNoChild()
isChildOf(string $parentPageFileName)
hasPageName(string $pageName)
hasDynamicChild(string $dynamicChildName)
usesFileName(string $fileName)
Page linking
There are multiple ways of linking between pages and generating URLs to do so. You can
- Generate a URL based on the page's file name using the
URLFromFile
class. - Generate a URL out of a
Page
object using theURLFromPage
class.
You can read more about generating URLs under the section URLs and links.