Frontend requests

When handling frontend web requests, TYPO3 automatically sets up a rich context that is used to render content and generate links. Several objects are created and configured during this process:

  • ContentObjectRenderer (cObj) – Responsible for processing TypoScript-based rendering, including typolink and other link generation tasks.
  • page Attribute – Holds the current page context and is used by many rendering processes.
  • PageInformation Object: Provides additional metadata about the current page.
  • Router: Ensures proper URL resolution.
  • FrontendTypoScriptFactory: Collects TypoScript and provides settings like linkAccessRestrictedPages and typolinkLinkAccessRestrictedPages.

These components work together only because the frontend request bootstrap initializes them with all the necessary data.

Limitations when there is no frontend request

When executing code outside of a frontend request (for example, in a CLI command), this context is missing:

  • The ContentObjectRenderer (cObj) can be instantiated manually, but it will not have a populated data array because there is no tt_content record. As a result, TypoScript properties like field = my_field or data = my_data will not work as expected.
  • The FrontendTypoScriptFactory is not set up.

Understanding this difference is crucial when writing custom code that depends on frontend rendering behavior but runs in a different context.

Simulating a frontend request

It may be necessary to simulate a frontend request to make certain functionality available where it would usually not be available.

For example, you might need to simulate a frontend request to be able to send a FluidEmail from a CLI / Console command context.

To simulate a frontend request you need, at a minimum, a site. If the current site is not defined you can use the SiteFinder to find one.

The following example demonstrates how to set up a basic frontend request with applicationType and site attributes:

use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\SiteFinder;

$site = $this->siteFinder->getSiteByPageId(1);
$request = (new ServerRequest())
    ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE)
    ->withAttribute('site', $site);
Copied!

For a complete example on how to send a FluidEmail with a console command see Example: Sending a FluidEmail via console command.

At this stage, the simulated frontend request still lacks page-related information and does not load TypoScript. It is still only a simplified simulation.

If you rely on any of these methods you will need to bootstrap them before using them.