Documentation

Pages
in package

Class Pages

Table of Contents

Properties

$active_lang  : string
$base  : string
$baseRoute  : array<string|int, string>
$blueprints  : Blueprints
$check_method  : string
$children  : array<string|int, mixed>
$enable_pages  : bool
$fire_events  : bool
$grav  : Grav
$home_route  : string|null
$ignore_files  : array<string|int, string>
$ignore_folders  : array<string|int, string>
$ignore_hidden  : bool
$index  : array<string|int, PageInterface|string>
$initialized  : bool
$instances  : array<string|int, PageInterface>
$last_modified  : int
$pages_cache_id  : string
$routes  : array<string|int, string>
$simple_pages_hash  : string
$sort  : array<string|int, mixed>
$types  : Types|null
$directory  : FlexDirectory|null

Methods

__construct()  : mixed
Constructor
accessLevels()  : array<string|int, mixed>
Get access levels of the site pages
addPage()  : void
Adds a page and assigns a route to it.
all()  : Collection
Get all pages
ancestor()  : PageInterface|null
Get a page ancestor.
base()  : string
Get or set base path for the pages.
baseRoute()  : string
Get base route for Grav pages.
baseUrl()  : string
Get base URL for Grav pages.
blueprints()  : Blueprint
Get a blueprint for a page type.
children()  : Collection
Get children of the path.
disablePages()  : void
Method used in admin to disable frontend pages from being initialized.
dispatch()  : PageInterface|null
Dispatch URI to a page.
enablePages()  : void
Method used in admin to later load frontend pages.
find()  : PageInterface|null
Find a page based on route.
get()  : PageInterface|null
Get a page instance.
getCollection()  : PageCollectionInterface|Collection
Get a collection of pages in the given context.
getDirectory()  : FlexDirectory|null
getHomeRoute()  : string
Gets the home route
getList()  : array<string|int, mixed>
Get list of route/title of all pages. Title is in HTML.
getPagesCacheId()  : null|string
Get the Pages cache ID
getSimplePagesHash()  : null|string
Get the simple pages hash that is not md5 encoded, and isn't specific to language
getTypes()  : Types
Get available page types.
homeUrl()  : string
Get home URL for Grav site.
inherited()  : PageInterface|null
Get a page ancestor trait.
init()  : void
Class initialization. Must be called before using this class.
instances()  : array<string|int, PageInterface>
Returns a list of all pages.
lastModified()  : int|null
Get or set last modification time.
modularTypes()  : array<string|int, mixed>
Get available page types.
pageTypes()  : array<string|int, mixed>
Get template types based on page type (standard or modular)
parents()  : array<string|int, mixed>
Get available parents routes
parentsRawRoutes()  : array<string|int, mixed>
Get available parents raw routes.
referrerRoute()  : string|null
Get relative referrer route and language code. Returns null if the route isn't within the current base, language (if set) and route.
register()  : void
reset()  : void
Reset pages (used in search indexing etc).
resetHomeRoute()  : string|null
Needed for testing where we change the home route via config
resetPages()  : void
Accessible method to manually reset the pages cache
root()  : PageInterface
Get root page.
route()  : string
Get route for Grav site.
routes()  : array<string|int, mixed>
Returns a list of all routes.
setCheckMethod()  : void
sort()  : array<string|int, mixed>
Sort sub-pages in a page.
types()  : array<string|int, mixed>
Get available page types.
url()  : string
Get URL for Grav site.
arrayShuffle()  : array<string|int, mixed>
Shuffles an associative array
buildFlexPages()  : void
buildRegularPages()  : void
buildRootPage()  : Page
evaluate()  : Collection
findSiteBasedRoute()  : PageInterface|null
Check site based routes.
getPagesPaths()  : array<string|int, mixed>
getVersion()  : string
initFlexPages()  : void
getParents()  : array<string|int, mixed>
Get available parents routes

Properties

$active_lang

protected string $active_lang

$base

protected string $base = ''

$baseRoute

protected array<string|int, string> $baseRoute = []

$check_method

protected string $check_method

$children

protected array<string|int, mixed> $children

$enable_pages

protected bool $enable_pages = true

$fire_events

protected bool $fire_events = false

$home_route

protected static string|null $home_route

$ignore_files

protected array<string|int, string> $ignore_files

$ignore_folders

protected array<string|int, string> $ignore_folders

$ignore_hidden

protected bool $ignore_hidden

$initialized

protected bool $initialized = false

$last_modified

protected int $last_modified

$pages_cache_id

protected string $pages_cache_id

$routes

protected array<string|int, string> $routes = []

$simple_pages_hash

protected string $simple_pages_hash

$sort

protected array<string|int, mixed> $sort

Methods

__construct()

Constructor

public __construct(Grav $grav) : mixed
Parameters
$grav : Grav

accessLevels()

Get access levels of the site pages

public accessLevels() : array<string|int, mixed>
Return values
array<string|int, mixed>

addPage()

Adds a page and assigns a route to it.

public addPage(PageInterface $page[, string|null $route = null ]) : void
Parameters
$page : PageInterface

Page to be added.

$route : string|null = null

Optional route (uses route from the object if not set).

ancestor()

Get a page ancestor.

public ancestor(string $route[, string|null $path = null ]) : PageInterface|null
Parameters
$route : string

The relative URL of the page

$path : string|null = null

The relative path of the ancestor folder

Return values
PageInterface|null

base()

Get or set base path for the pages.

public base([string|null $path = null ]) : string
Parameters
$path : string|null = null
Return values
string

baseRoute()

Get base route for Grav pages.

public baseRoute([string|null $lang = null ]) : string
Parameters
$lang : string|null = null

Optional language code for multilingual routes.

Return values
string

baseUrl()

Get base URL for Grav pages.

public baseUrl([string|null $lang = null ][, bool|null $absolute = null ]) : string
Parameters
$lang : string|null = null

Optional language code for multilingual links.

$absolute : bool|null = null

If true, return absolute url, if false, return relative url. Otherwise return default.

Return values
string

blueprints()

Get a blueprint for a page type.

public blueprints(string $type) : Blueprint
Parameters
$type : string
Return values
Blueprint

children()

Get children of the path.

public children(string $path) : Collection
Parameters
$path : string
Return values
Collection

disablePages()

Method used in admin to disable frontend pages from being initialized.

public disablePages() : void

dispatch()

Dispatch URI to a page.

public dispatch(string $route[, bool $all = false ][, bool $redirect = true ]) : PageInterface|null
Parameters
$route : string

The relative URL of the page

$all : bool = false

If true, return also non-routable pages, otherwise return null if page isn't routable

$redirect : bool = true

If true, allow redirects

Tags
throws
Exception
Return values
PageInterface|null

enablePages()

Method used in admin to later load frontend pages.

public enablePages() : void

find()

Find a page based on route.

public find(string $route[, bool $all = false ]) : PageInterface|null
Parameters
$route : string

The route of the page

$all : bool = false

If true, return also non-routable pages, otherwise return null if page isn't routable

Return values
PageInterface|null

get()

Get a page instance.

public get(string $path) : PageInterface|null
Parameters
$path : string

The filesystem full path of the page

Tags
throws
RuntimeException
Return values
PageInterface|null

getHomeRoute()

Gets the home route

public static getHomeRoute() : string
Return values
string

getList()

Get list of route/title of all pages. Title is in HTML.

public getList([PageInterface|null $current = null ][, int $level = 0 ][, bool $rawRoutes = false ][, bool $showAll = true ][, bool $showFullpath = false ][, bool $showSlug = false ][, bool $showModular = false ][, bool $limitLevels = false ]) : array<string|int, mixed>
Parameters
$current : PageInterface|null = null
$level : int = 0
$rawRoutes : bool = false
$showAll : bool = true
$showFullpath : bool = false
$showSlug : bool = false
$showModular : bool = false
$limitLevels : bool = false
Return values
array<string|int, mixed>

getPagesCacheId()

Get the Pages cache ID

public getPagesCacheId() : null|string

this is particularly useful to know if pages have changed and you want to sync another cache with pages cache - works best in onPagesInitialized()

Return values
null|string

getSimplePagesHash()

Get the simple pages hash that is not md5 encoded, and isn't specific to language

public getSimplePagesHash() : null|string
Return values
null|string

getTypes()

Get available page types.

public static getTypes() : Types
Return values
Types

homeUrl()

Get home URL for Grav site.

public homeUrl([string|null $lang = null ][, bool|null $absolute = null ]) : string
Parameters
$lang : string|null = null

Optional language code for multilingual links.

$absolute : bool|null = null

If true, return absolute url, if false, return relative url. Otherwise return default.

Return values
string

inherited()

Get a page ancestor trait.

public inherited(string $route[, string|null $field = null ]) : PageInterface|null
Parameters
$route : string

The relative route of the page

$field : string|null = null

The field name of the ancestor to query for

Return values
PageInterface|null

init()

Class initialization. Must be called before using this class.

public init() : void

lastModified()

Get or set last modification time.

public lastModified([int|null $modified = null ]) : int|null
Parameters
$modified : int|null = null
Return values
int|null

modularTypes()

Get available page types.

public static modularTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

pageTypes()

Get template types based on page type (standard or modular)

public static pageTypes([string|null $type = null ]) : array<string|int, mixed>
Parameters
$type : string|null = null
Return values
array<string|int, mixed>

parents()

Get available parents routes

public static parents() : array<string|int, mixed>
Return values
array<string|int, mixed>

parentsRawRoutes()

Get available parents raw routes.

public static parentsRawRoutes() : array<string|int, mixed>
Return values
array<string|int, mixed>

referrerRoute()

Get relative referrer route and language code. Returns null if the route isn't within the current base, language (if set) and route.

public referrerRoute(string|null &$langCode[, string $route = '/' ]) : string|null
Parameters
$langCode : string|null

Variable to store the language code. If already set, check only against that language.

$route : string = '/'

Optional route within the site.

Tags
example

$langCode = null; $referrer = $pages->referrerRoute($langCode, '/admin'); returns relative referrer url within /admin and updates $langCode

example

$langCode = 'en'; $referrer = $pages->referrerRoute($langCode, '/admin'); returns relative referrer url within the /en/admin

since
1.7.23
Return values
string|null

register()

public register() : void

reset()

Reset pages (used in search indexing etc).

public reset() : void

resetHomeRoute()

Needed for testing where we change the home route via config

public static resetHomeRoute() : string|null
Return values
string|null

resetPages()

Accessible method to manually reset the pages cache

public resetPages(array<string|int, mixed> $pages_dirs) : void
Parameters
$pages_dirs : array<string|int, mixed>

route()

Get route for Grav site.

public route([string $route = '/' ][, string|null $lang = null ]) : string
Parameters
$route : string = '/'

Optional route to the page.

$lang : string|null = null

Optional language code for multilingual links.

Return values
string

routes()

Returns a list of all routes.

public routes() : array<string|int, mixed>
Return values
array<string|int, mixed>

setCheckMethod()

public setCheckMethod(string $method) : void
Parameters
$method : string

sort()

Sort sub-pages in a page.

public sort(PageInterface $page[, string|null $order_by = null ][, string|null $order_dir = null ][, mixed $sort_flags = null ]) : array<string|int, mixed>
Parameters
$page : PageInterface
$order_by : string|null = null
$order_dir : string|null = null
$sort_flags : mixed = null
Return values
array<string|int, mixed>

types()

Get available page types.

public static types() : array<string|int, mixed>
Return values
array<string|int, mixed>

url()

Get URL for Grav site.

public url([string $route = '/' ][, string|null $lang = null ][, bool|null $absolute = null ]) : string
Parameters
$route : string = '/'

Optional route to the page.

$lang : string|null = null

Optional language code for multilingual links.

$absolute : bool|null = null

If true, return absolute url, if false, return relative url. Otherwise return default.

Return values
string

arrayShuffle()

Shuffles an associative array

protected arrayShuffle(array<string|int, mixed> $list) : array<string|int, mixed>
Parameters
$list : array<string|int, mixed>
Return values
array<string|int, mixed>

buildRegularPages()

protected buildRegularPages() : void

buildRootPage()

protected buildRootPage() : Page
Return values
Page

findSiteBasedRoute()

Check site based routes.

protected findSiteBasedRoute(string $route) : PageInterface|null
Parameters
$route : string
Return values
PageInterface|null

getPagesPaths()

protected getPagesPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>

getVersion()

protected getVersion() : string
Return values
string

initFlexPages()

protected initFlexPages() : void

getParents()

Get available parents routes

private static getParents(bool $rawRoutes) : array<string|int, mixed>
Parameters
$rawRoutes : bool

get the raw route or the normal route

Return values
array<string|int, mixed>

        
On this page

Search results