2017 © Pedro PelĂĄez
 

typo3-cms-extension contexts

image

netresearch/contexts

  • Tuesday, July 31, 2018
  • by copitz
  • Repository
  • 16 Watchers
  • 4 Stars
  • 261 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 4 Open issues
  • 18 Versions
  • 7 % Grown

The README.md

Latest version License PHPStan PHPCodeSniffer CodeQL, (*1)

Multi-channel contexts

Show and hide pages and content elements based on configurable "contexts". With the use of contexts, TYPO3 is able to do multichannel output., (*2)

Examples for contexts:, (*3)

  • Screen size < 500px
  • Browser runs on a tablet or mobile phone
  • Location is 15km around a certain place
  • User is from one of certain countries
  • User entered website with GET-Parameter affID=foo
  • User IP matches a given rule
  • A session variable is set
  • A combination of any other rules

Apart from the context rules, this extension also provides an API to use contexts in your own extensions., (*4)

* Multi-channel contexts * Setup * Creating and using contexts * Creating a context * Using a context * Context types * Domain * Domain matching * GET parameter * IP address * HTTP header * Logical context combination * Fluid template implementation * TypoScript implementation , (*5)

Setup

  1. Install and activate extension contexts
  2. Clear TYPO3 cache

Optional: Install extensions contexts_geolocation for location-based context rules (continent, country, area) and contexts_wurfl for device-based rules (type check: phone, tablet, TV, ...; screen sizes, device/browser type)., (*6)

Creating and using contexts

Creating a context

  1. Log into the TYPO3 backend as administrator
  2. Goto Web/List view, root page (ID 0)
  3. Create a new record: TYPO3 contexts -> Context
  • Give it a title, e.g. "Affiliate ID: foo"
  • Select a type: "GET parameter"
  • GET parameter name: affID
  • Parameter value: foo
  • Activate "Store result in user session"
  • Save and close

Using a context

  1. Goto Web/Page, select a page
  2. Edit a content element
  3. Select the "Contexts" tab
  4. For Context "Affiliate ID: foo", select "Visible: yes"
  5. Save

View the page. The content element is not visible., (*7)

Now add ?affID=foo to the URL and load it. The content element will be visible now., (*8)

You can visit other pages now. When you come back, the content element will still be visible - even though the GET parameter is not in the URL anymore - because "Store result in user session" had been activated., (*9)

Context types

The contexts extension ships with a number of simple contexts. All of them get stored in table tx_contexts_contexts., (*10)

Domain

A domain context matches when the domain the user visits is in the configured list., (*11)

This is helpful if the site is available on several domains, or when it is deployed on development/stage/live systems - you may choose to show a content element on the development system only., (*12)

Domain matching

You may use one domain per line., (*13)

When the domain does not begin with a dot, it will only match fully: www.example.org will not match the configured domain example.org., (*14)

It is possible to use a dot in front of the domain name. In this case, all subdomains will match: some.www.example.org matches the configured domain .example.org., (*15)

GET parameter

Checks if a GET parameter is available and has a certain value., (*16)

Activate "Store result in user session" to keep the context when navigating between pages., (*17)

When leaving the parameter values field empty, any non-empty parameter value will activate the context., (*18)

IP address

Matches the user's IP address. IPv4 and IPv6 are supported., (*19)

Supported notations:, (*20)

  • Full addresses: 80.76.201.32
  • Prefix: 80.76.201.32/27, FE80::/16
  • Wildcards: 80.76.201.*, 80.76.*.37, 80.76.*.*

HTTP header

Checks if an HTTP header is available and has a certain value., (*21)

Activate "Store result in user session" to keep the context when navigating between pages., (*22)

When leaving the parameter values field empty, any non-empty parameter value will activate the context., (*23)

Logical context combination

Combines other contexts with logical operators., (*24)

Contexts are referenced via their alias and can be combined with the following signs:, (*25)

  • logical and: &&
  • logical or: ||
  • negation: !
  • parentheses to group parts of expressions: (...)

Session variable

This context checks if a session variable with the given name is set (is not NULL)., (*26)

Fluid template implementation

The implementation of a context query in fluid templates looks like::, (*27)

<div xmlns="http://www.w3.org/1999/xhtml" xmlns:contexts="http://typo3.org/ns/Tx_Contexts_ViewHelpers">
    <f:if condition="{contexts:matches(alias:'mobile')}">
        <f:then>is Mobile</f:then>
        <f:else>is not Mobile</f:else>
    </f:if>
</div>

TypoScript implementation

The implementation of a context query in TypoScript looks like::, (*28)

[contextMatch("mobile")]
    # do something, it's a mobile browser
[END]

Testing

composer update
vendor/bin/phpcs Classes/ --standard=PSR12
vendor/bin/phpstan analyse --configuration phpstan.neon
vendor/bin/rector --dry-run

The Versions

31/07 2018

0.5.x-dev

0.5.9999999.9999999-dev

  Sources   Download

02/04 2018

v0.1.0

0.1.0.0

  Sources   Download

02/04 2018

v0.2.0

0.2.0.0

  Sources   Download

02/04 2018

v0.4.3

0.4.3.0

  Sources   Download

02/04 2018

v0.5.0

0.5.0.0

  Sources   Download

02/04 2018

v0.5.1

0.5.1.0

  Sources   Download

02/04 2018

v0.5.2

0.5.2.0

  Sources   Download

02/04 2018

v0.2.1

0.2.1.0

  Sources   Download

02/04 2018

v0.3.0

0.3.0.0

  Sources   Download

02/04 2018

v0.3.1

0.3.1.0

  Sources   Download

02/04 2018

v0.4.0

0.4.0.0

  Sources   Download

02/04 2018

v0.4.1

0.4.1.0

  Sources   Download

02/04 2018

v0.4.2

0.4.2.0

  Sources   Download

21/08 2017

dev-analysis-8mojgD

dev-analysis-8mojgD https://www.netresearch.de

Contexts for TYPO3 - can be used to modify page behaviour in the frontend based on several conditions

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

extension typo3 contexts

21/08 2017

dev-master

9999999-dev https://www.netresearch.de

Contexts for TYPO3 - can be used to modify page behaviour in the frontend based on several conditions

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

extension typo3 contexts

21/08 2017

dev-analysis-z93OP6

dev-analysis-z93OP6 https://www.netresearch.de

Contexts for TYPO3 - can be used to modify page behaviour in the frontend based on several conditions

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

extension typo3 contexts

30/05 2017

dev-analysis-zR0Plx

dev-analysis-zR0Plx https://www.netresearch.de

Contexts for TYPO3 - can be used to modify page behaviour in the frontend based on several conditions

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

extension typo3 contexts

10/01 2017

v1.0.0

1.0.0.0 https://www.netresearch.de

Contexts for TYPO3 - can be used to modify page behaviour in the frontend based on several conditions

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

extension typo3 contexts