PHPackages                             netzmacht/contao-page-context - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. netzmacht/contao-page-context

ActiveContao-bundle[Utility &amp; Helpers](/categories/utility)

netzmacht/contao-page-context
=============================

This library provides tools to bootstrap the contao page contexts for custom routes.

1.2.3(4mo ago)319.9k↓22.2%1[3 PRs](https://github.com/netzmacht/contao-page-context/pulls)2LGPL-3.0-or-laterPHPPHP ^8.1CI passing

Since Nov 1Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/netzmacht/contao-page-context)[ Packagist](https://packagist.org/packages/netzmacht/contao-page-context)[ GitHub Sponsors](https://github.com/dmolineus)[ RSS](/packages/netzmacht-contao-page-context/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (16)Versions (17)Used By (2)

Contao Page Context
===================

[](#contao-page-context)

[![Build Status](https://github.com/netzmacht/contao-page-context/actions/workflows/diagnostics.yml/badge.svg)](https://github.com/netzmacht/contao-page-context/actions/workflows/diagnostics.yml)[![Version](https://camo.githubusercontent.com/8ffd89465b845cae37714070eb47efa11bd2d939b9909e79033d832abe97513b/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65747a6d616368742f636f6e74616f2d706167652d636f6e746578742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/contao-page-context)[![License](https://camo.githubusercontent.com/0c7558e484eed28d0fa049112c00e9ecdfc2edd957c9220b4059c13dc1d4c0ff/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e65747a6d616368742f636f6e74616f2d706167652d636f6e746578742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/contao-page-context)[![Downloads](https://camo.githubusercontent.com/c43675d5904020cd21ecc1017641ae847568c87c3560450882c9565649d53d0e/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e65747a6d616368742f636f6e74616f2d706167652d636f6e746578742e7376673f7374796c653d666c61742d737175617265)](http://packagist.org/packages/netzmacht/contao-page-context)[![Contao Community Alliance coding standard](https://camo.githubusercontent.com/5c83beb382413cbfa523bbea12d70d0723a803b3f7cbba029609ed1848dfa99b/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6363612d636f64696e675f7374616e646172642d7265642e7376673f7374796c653d666c61742d737175617265)](https://github.com/contao-community-alliance/coding-standard)

This Contao extension allows developer manually boot the page context of Contao when using custom routes.

Parts of the Contao CMS relies on the existing of global state initialized when rendering a page. Modules, content elements, insert tags and custom extensions might rely that this state is initialized.

For instance Contao developers access the `$GLOBALS['objPage']` as there is no other way to get the current page.

However, when using a custom entrypoint, for example for an API, you don't have this state initialized. Using the Contao library and functionality might end in unexpected errors.

This is the point there this extension steps in. It allows you to boot the page context manually for your route.

In detail it, initialize following steps:

- The Contao framework
- Constant `BE_USER_LOGGED_IN` and `FE_USER_LOGGED_IN` to `false` if not defined.
- Loading the page from the database
- Globals `objPage`, `TL_ADMIN_NAME`, `TL_ADMIN_EMAIL`, `TL_KEYWORDS`, `TL_LANGUAGE`
- Initialize the locale of the request and the translator
- Loads the default language file
- Calls `Controller::initializeStaticUrls()`
- Initializes the page layout (triggers `getPageLayout` hook)

Requirements
------------

[](#requirements)

- Contao `^4.13 || ^5.3`
- PHP `^8.1`

Installation
------------

[](#installation)

```
php composer.phar require netzmacht/contao-page-context --update-no-dev -o

```

Usage
-----

[](#usage)

### 1. Implement a PageIdDeterminator and register it properly

[](#1-implement-a-pageiddeterminator-and-register-it-properly)

First you have to provide a PageIdDeterminator. It's responsible to extract the page id from the given request.

You should limit the determinator to your special use case, that's why there is the `match()` method.

```
