netresearch/contexts
Multi-channel content visibility for TYPO3 - by Netresearch
Maintainers
Package info
github.com/netresearch/t3x-contexts
Type:typo3-cms-extension
pkg:composer/netresearch/contexts
Requires
- php: ^8.2
- ext-pdo: *
- typo3/cms-backend: ^12.4 || ^13.4
- typo3/cms-core: ^12.4 || ^13.4
- typo3/cms-extbase: ^12.4 || ^13.4
- typo3/cms-extensionmanager: ^12.4 || ^13.4
- typo3/cms-frontend: ^12.4 || ^13.4
Requires (Dev)
- a9f/typo3-fractor: ^0.5.8
- captainhook/captainhook: ^5.28
- captainhook/hook-installer: ^1.0
- friendsofphp/php-cs-fixer: ^3.92
- infection/infection: *
- nikic/php-fuzzer: ^0.0.11
- phpat/phpat: ^0.12
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0 || ^13.0
- rector/rector: ^2.3
- squizlabs/php_codesniffer: ^4.0
- ssch/typo3-rector: ^3.11
- typo3/testing-framework: ^8.0 || ^9.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
AGPL-3.0-or-later 86cc0a2cf2c06b7ffdc855fbe8843ed0cd34f7e8
This package is auto-updated.
Last update: 2026-06-27 08:41:47 UTC
README
Multi-channel Contexts
Content visibility control for TYPO3 based on configurable contexts
π CI
π Codecov
π Documentation
π OpenSSF Scorecard
π OpenSSF Best Practices
π PHPStan
π PHP 8.2-8.5
π TYPO3 v12 | v13
π License
π Latest Release
π Contributor Covenant
π SLSA 3
Show and hide pages and content elements based on configurable "contexts". With the use of contexts, TYPO3 is able to do multichannel output.
Requirements
| Version | TYPO3 | PHP |
|---|---|---|
| 4.x | 12.4, 13.4 | 8.2 - 8.5 |
| 3.x | 11.5 | 7.4 - 8.1 |
Context Examples
- User IP matches a given rule
- User entered website with GET-Parameter
affID=foo - Domain the user visits
- HTTP header values (User-Agent, Accept-Language, etc.)
- A session variable is set
- A combination of any other rules
With companion extensions:
- Screen size < 500px (
contexts_wurfl) - Browser runs on a tablet or mobile phone (
contexts_wurfl) - Location is 15km around a certain place (
contexts_geolocation) - User is from one of certain countries (
contexts_geolocation)
Apart from the context rules, this extension also provides an API to use contexts in your own extensions.
Table of Contents
Setup
- Install and activate extension
contexts - Clear TYPO3 cache
composer require netresearch/contexts vendor/bin/typo3 extension:activate contexts vendor/bin/typo3 cache:flush vendor/bin/typo3 database:updateschema
Optional Extensions:
contexts_geolocation- Location-based rules (continent, country, area)contexts_wurfl- Device-based rules (phone, tablet, TV, screen sizes)
Creating and Using Contexts
Creating a Context
- Log into the TYPO3 backend as administrator
- Go to Web/List view, root page (ID 0)
- Create a new record: TYPO3 contexts β Context
- Configure:
- Title: e.g., "Affiliate ID: foo"
- Type: "GET parameter"
- Parameter name:
affID - Parameter value:
foo - Enable "Store result in user session"
- Save and close
Using a Context
- Go to Web/Page, select a page
- Edit a content element
- Select the "Contexts" tab
- For your context, select "Visible: yes"
- Save
The content element is now only visible when the context matches.
Context Types
Domain
Match based on the accessed domain name.
- One domain per line
- Without leading dot: exact match only (
www.example.orgβexample.org) - With leading dot: matches all subdomains (
.example.orgmatcheswww.example.org)
Query Parameter
Match based on URL query parameters.
- Enable "Store result in user session" to persist across pages
- Leave value empty to match any non-empty parameter value
IP Address
Match the user's IP address. IPv4 and IPv6 supported.
80.76.201.32 # Full address
80.76.201.32/27 # CIDR notation
FE80::/16 # IPv6 prefix
80.76.201.* # Wildcard
80.76.*.* # Multiple wildcards
HTTP Header
Match HTTP request headers (User-Agent, Accept-Language, X-Forwarded-For, etc.)
- Enable "Store result in user session" to persist across pages
- Leave value empty to match any non-empty header value
Session Variable
Match based on session data. Checks if a session variable with the given name exists.
Logical Combination
Combine multiple contexts with logical operators:
| Operator | Description |
|---|---|
&& |
Logical AND |
| ` | |
! |
Negation |
(...) |
Grouping |
Example: mobile && !tablet
Integration
Fluid Templates
<html xmlns:contexts="http://typo3.org/ns/Netresearch/Contexts/ViewHelpers"> <f:if condition="{contexts:matches(alias: 'mobile')}"> <f:then>Mobile content</f:then> <f:else>Desktop content</f:else> </f:if> </html>
TypoScript Conditions
[contextMatch('mobile')]
page.10.template = EXT:site/Resources/Private/Templates/Mobile.html
[END]
PHP API
use Netresearch\Contexts\Api\ContextMatcher; if (ContextMatcher::getInstance()->matches('mobile')) { // Mobile-specific logic }
Development
Testing
composer install # Run unit tests composer ci:test:php:unit # Run functional tests (requires database) composer ci:test:php:functional # Run with coverage composer test:coverage # Docker-based testing (no local PHP needed) ./Build/Scripts/runTests.sh -s unit ./Build/Scripts/runTests.sh -s phpstan ./Build/Scripts/runTests.sh -h # Show all options
Code Quality
# Static analysis (level 10) composer ci:test:php:phpstan # Code style check composer ci:test:php:cgl # Code style fix composer ci:cgl
| Tool | Version | Purpose |
|---|---|---|
| PHPUnit | 10/11/12/13 | Unit and functional tests |
| PHPStan | 2.x | Static analysis (level 10) |
| PHP-CS-Fixer | 3.x | Code style (PSR-12) |
Documentation
Full documentation available at docs.typo3.org.
License
This project is licensed under the AGPL-3.0-or-later.
Credits
Developed and maintained by Netresearch DTT GmbH.
Contributors: Andre HΓ€hnel, Christian Opitz, Christian Weiske, Marian Pollzien, Rico Sonntag, Benni Mack, and others.
